【问题标题】:Pass an array from stacknavigator as a prop to screen react native navigation?将stacknavigator中的数组作为道具传递给屏幕反应原生导航?
【发布时间】:2020-08-04 03:24:03
【问题描述】:
  state = {
    title: []
  }
  render() {
    return (<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Dashboard"
component={Dashboard}
initialParams={{title:this.state.title}}
/>
</Stack.Navigator>
      </NavigationContainer>}
export default class Dashboard extends React.Component {
    constructor(prop) {
        super(prop);
        console.log(  this.props.route.params)
        this.state = {
            search:"",
templist:this.props.route.params.title,
            title: this.props.route.params.title}

**我想将状态中的标题(数组)传递给屏幕 但我没有在屏幕上看到数组**

【问题讨论】:

  • 您是否在已放入的日志中获取参数?
  • 不!我得到未定义的值

标签: reactjs react-native state react-navigation prop


【解决方案1】:

遇到了类似的问题。通过对我试图传递的数组进行字符串化使其工作

{title: JSON.stringify(this.state.title)}

【讨论】:

    猜你喜欢
    • 2018-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-24
    • 1970-01-01
    • 2022-10-07
    • 1970-01-01
    相关资源
    最近更新 更多