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]()'? –