【问题标题】:null is not an object (evaluating 't().store') - React Native Exponull 不是对象(评估 't().store') - React Native Expo
【发布时间】:2021-08-30 17:20:58
【问题描述】:

我是世博会的新手。我希望能够通过网络使用 Expo,但遇到了一些问题。

瞄准

我想获取一个出现的例句in red drawn area 根据用户对不定冠词按钮或定冠词按钮的按下。 这两个例句是从...中选择的……

//SampleSentences.js
const SampleSentencesEnglish = {
    'indefinite': <Text>"A man was looking for you"</Text>,
    'definite': <Text>"The man was looking for you"</Text>,
  }

问题 我正在使用 Redux 和 我注释掉了一些行,因为每当我允许const dispatch = useDispatch(); 要么 const currentArticleType= useSelector(articleSelector)

报错

null 不是对象(评估 't().store')

解决方案

难道是因为除了在package.json 中写库名之外,我在库安装中没有做一些额外的步骤?除了编写带有版本的库名称之外,是否需要额外的步骤?

请检查 https://snack.expo.io/@uygarucar/hazardous-sandwich


出现错误的代码 sn-p

//App.js
...
const App = (props) => {
  
  //const dispatch = useDispatch();
  
  const _adjustIndefinite = () => {
    dispatch(setArticleAC('indefinite'));
  };

  const _adjustDefinite = () => {
    dispatch(setArticleAC('definite'));
  };

  //const currentArticleType= useSelector(articleSelector)


  
  return (
    <Provider store={store}>
      <View style={styles.container}>
        <TouchableOpacity onPress={_adjustIndefinite}>
          <Text>indefinite article</Text>
        </TouchableOpacity>
        <TouchableOpacity onPress={_adjustDefinite}>
          <Text>definite article</Text>
        </TouchableOpacity>
        <Text> </Text>
        <Text>Sample Sentence</Text>
        {/*<Text>{sampleSentencesEnglish[currentArticleType]}</Text>*/}
      </View>  
    </Provider>
  );
};

...

【问题讨论】:

    标签: react-native react-redux expo


    【解决方案1】:

    当我从 Expo 切换到 React Native CLI(我猜它是这样称呼的)时,出现了一条更容易理解的消息。

    找不到 react-redux 上下文值;请确保组件 被包裹在一个

    根据这个thread,使用useDispatch的组件应该已经被提供者包装了。

    从上面的案例改为这个解决了我的问题。

    <Provider store={store}>
      <MainApp/>
    </Provider>
    

    注意,我们使用 useDispatch 的组件这次是在 Provider 内部(MainApp 是我们使用 useDispatch 的地方)。

    工作样本: https://snack.expo.io/@uygarucar/9b9e72

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-19
      • 2021-10-27
      • 2019-10-18
      相关资源
      最近更新 更多