简体   繁体   中英

React native router flux to child component

Version

Tell us which versions you are using:

  • react-native-router-flux 4.0.0-beta.22
  • react-native SDK 28

I have structure router.

const scenes2 = Actions.create(
      <Stack key="root" tabs={true} tabBarPosition={'bottom'} hideNavBar>
        <Stack key="home" hideNavBar={true} component={Home} type={ActionConst.REPLACE} title="Home" titleStyle={styles.menutab} initial={true} icon={TabIcon} image={require('@images/icon-bag.png')}>
          <Scene key="postDetails" component={PostDetails} title="Post" />
        </Stack>
        <Stack key="video" hideNavBar={true} component={Video} title="Video" icon={TabIcon} image={require('@images/icon-bag.png')}>
          <Scene key="videoDetails" component={VideoDetails} title="VideoDetails" />
        </Stack>
        <Stack key="persija" hideNavBar={true} component={Home} title="Persija" icon={TabIcon} image={require('@images/icon-bag.png')}>

        </Stack>
        <Stack key="shop" hideNavBar={true} component={Product} title="Shop" icon={TabIcon} image={require('@images/icon-bag.png')}>

        </Stack>
        <Stack key="profile" hideNavBar={true} component={Profile} title="Profile" icon={TabIcon} image={require('@images/icon-bag.png')}>

        </Stack>
      </Stack>
    );

And button on press.

<TouchableOpacity onPress={() => {
    Actions.postDetails.bind(this, {post: post});
}}
style={news.bannerText}>
<Text style={news.bannerTitle}>{postTitle}</Text>
<Text style={news.bannerDate}><TimeAgo time={post.date}/></Text>
</TouchableOpacity>

Get error Undefinded is not a object (evluating _reactNativeRouterFlux.Actions.postDetails.bind()

Wellcome to SO. Actual code for onPress is as below:

<TouchableOpacity onPress={() => {
    Actions.postDetails({post: post});
}}
style={news.bannerText}>
<Text style={news.bannerTitle}>{postTitle}</Text>
<Text style={news.bannerDate}><TimeAgo time={post.date}/></Text>
</TouchableOpacity>

Here when you are using Actions.fileKey() then you don't need to bind that just pass parameters simple way. For your furthur knowledge about binding a function please refer this link and for Actions/router-flux please refer this link

Hope it will help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM