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:
- React Hook “useState“ is called in function “xxx“ which is neither a React function component or
- Webpack packaging error TypeError: this.getOptions is not a function at Object.lessLoader
- Taro Install Error: permission denied, symlink ‘../lib/node_modules/@tarojs/cli/bin/taro‘ -> ‘/usr/local/bin/tar
- TypeError: res.render is not a function
- [Solved] umi Project Create Error: Rendered more hooks or Rendered fewer hooks
- Syntax Error: TypeError: this.getOptions is not a function
- TypeError: db.collection is not a function
- TypeError: ‘WebElement’ object is not iterable error
- [Solved] MongoDB Error: TypeError: Object of type ObjectId is not JSON serializable
- Webpack Error: Module build failed: TypeError: this.getOptions is not a function
- Hive Error: FAILED: RuntimeException Error loading hooks(hive.exec.post.hooks): java.lang.ClassNotFoundException: org.apache.atlas.hive.hook.HiveHook
- [Solved] swiper Error: The requested module ‘react’ is expected to be of type CommonJS, which does not support named exports. CommonJS modules can be imported by importing the default export
- Taro Error: chunk common [mini-css-extract-plugin] Conflicting order between: ……
- QT solves error: use of deleted function and is private within this context
- Solve the data transfer between vue irrelevant components error: this.$store.commit is not a function
- Attempted import error: ‘mobx-react‘ does not contain a default export (imported as ‘observer‘).
- [Solved] react Error: Can‘t perform a React state update on an unmounted component
- [Solved] MindSpore Network custom reverse error: TypeError: The params of function ‘bprop’ of
- [Solved] Virtualenvwrapper.sh error: There was a problem running the initialization hooks.