Hooks报错TypeError: Object(...) is not a function



  • import Taro, { useState } from '@tarojs/taro'
    
    setHooksTest = () => {
        const [style, setStyle] = useState({
          background:'red',
          color:'blue'
        })
        return <View 
                style={{background: style.background, color: style.color}}
                onClick={()=>{setStyle({background:'green', color:'#ccc'})}}
                >
                测试
              </View>
      }
    

    render之后一直报错TypeError: Object(...) is not a function

    TypeError: Object(...) is not a function
        at Goods.setHooksTest (index.jsx:160)
        at Goods.render (index.jsx:58)
        at ye (react-reconciler.production.min.js:90)
        at xe (react-reconciler.production.min.js:89)
        at ig (react-reconciler.production.min.js:162)
        at hg (react-reconciler.production.min.js:139)
        at bg (react-reconciler.production.min.js:138)
        at Of (react-reconciler.production.min.js:132)
        at react-reconciler.production.min.js:30
        at push../node_modules/scheduler/cjs/scheduler.production.min.js.exports.unstable_runWithPriority (scheduler.production.min.js:18)
    

    有谁知道是什么原因吗?



  • 版本:
    taro:3.0.18
    react:^16.10.0



  • 3.x之后要求这么用
    import {useState} from 'react'


登录后回复