如何在带有返回对象的函数中使用钩子

时间:2021-07-22 17:53:56

标签: react-native

我正在尝试使用 react-redux 将主题切换与暗模式和亮模式一起使用。

颜色.js

import { useSelector } from 'react-redux';

const darkMode = {
        primary: 'black',
        secondary: 'white',
}

const lightMode = {
        primary: 'white',
        secondary: 'black',
}

function ColorMode(){
    const mode  = useSelector(state => state.getDarkMode.darkMode);   // Calling from redux saga
    return mode ? darkMode : lightMode
}

App.js

import { useSelector } from 'react-redux';
import Color from 'Color';

const App = () => {
   console.log('Here it is working...', Color.primary) // black
   return (
      <View style={{backgroundColor: Color.primary}} /> // Here not working 
         <Text style={{color: Color.secondary}} />  // Here not working
      </View>
   )
} 

错误:呈现的钩子比预期的少。这可能是由于意外的提前退货声明造成的。

0 个答案:

没有答案