Taro Use React Hooks Error: TypeError: Object(…) is not a function

  I stepped on a version of the pit today

In the taro project, you want to use react hooks. The code is as follows. Errors are always reported in the wechat development tool

After looking at the official documents, I found that taro was introduced after version 3.xx   Usestate and so on need to be introduced from the corresponding framework react

The code is modified as follows:

// React Hooks
import { useState, useEffect } from 'react' 
import { View, Text } from '@tarojs/components'
import './index.scss'
function Index() {
    const [userName, setUserName] = useState('Ashely')
    return (
        <View>
            <Text>{userName}</Text>
        </View>
    )
}

export default Index

You can compile normally

Read More: