1
我試圖發送一個RouteKey
道具,然後嘗試在鏈接函數中使用道具。發送道具,然後在React中使用它作爲函數?
這裏是我的組件:
<MenuItem RouterKey={'assetsList'} />
和組件的定義裏面,我想用它的行動中發揮作用,像這樣:
import { Actions } from 'react-native-router-flux';
const MenuItem = (props) => {
return (
<TouchableWithoutFeedback onPress={() => { return `${Actions}.${props.RouterKey}()`; }}>
<View>
//somethings here...
</View>
</TouchableWithoutFeedback>
);
};
基本上就是我想要做的是:
<TouchableWithoutFeedback onPress={() => { Actions.whateverWasPassed(); }}>
但是,我無法做到這一點。我在這裏錯過了什麼?我知道我這樣做的方式是錯誤的。什麼是正確的方法來做到這一點?
嘗試返回'$ {Actions}。$ {props.RouterKey}'();.反引號外的括號。如果它不起作用,那麼你也可以嘗試'Actions [props.routerKey]()' –
@HardikModha:嘗試...不工作.. –
你可以嘗試'Actions [props.routerKey]()'? –