问题描述
我正在将React Native与React-Native-Router-Flux一起用于导航。我正在尝试将“原始”值传递到指定为“初始”屏幕的场景以进行显示。这是一些代码:
Routes.js
import React from 'react'
import { Router,Scene } from 'react-native-router-flux'
import Home from './Home.js'
import Login from './Login.js'
const Routes = (props) => (
<Router>
<Scene key = "root">
<Scene key = "home" component = {Home} title = "Home" initial = {true} />
<Scene key = "login" component = {Login} title = "Login" />
</Scene>
</Router>
)
export default Routes
App.js
import React,{ Component } from 'react';
import { AppRegistry,View } from 'react-native';
import { Actions } from 'react-native-router-flux'
import Routes from './Routes.js'
class reactApp extends Component {
render() {
return (
<Routes
setUser={'unkNown'}
login={'false'}
email={'unkNown'}
logout={'false'}
/>
)
}
}
export default reactApp
AppRegistry.registerComponent('Cast4',() => Cast4)
Home.js
import React,{ useState,useContext,createContext } from 'react'
import { Button,TouchableOpacity,Text } from 'react-native';
import { Actions } from 'react-native-router-flux';
const Home = (props) => {
console.log('props called: ' + props); //[object Object]
console.log('props called: ' + props.setUser); //undefined
console.log('props called: ' + props.login); //undefined
console.log('props called: ' + props.email); //undefined
console.log('props called: ' + props.logout); //undefined
return (
//stuff in here
)
}
export default Home
我正在尝试将最初定义的值(setUser,登录名,电子邮件,注销)传递到定义为“初始” ...即“ Home.js”的场景。这些值未传递给“ Home.js”,因为它们是“未定义”的。我假设在输入“原始”值之后,我将能够传递更新/更改的值(例如在“登录”场景中)...我在这里做错了什么?任何建议都非常感谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)