我正在尝试调用API并使用useEffect更新React Typescript项目中的状态。
基本项目在“react-script@4.0.3”和typescript@latest
上运行
我正在尝试将新组件添加到Uniswap存储库-〉https://github.com/Uniswap/interface
这是我的组件
const { account, chainId, provider } = useWeb3React()
const [iconClicked, setIconCLicked] = useState(false)
const [notifications, setNotification] = useState<notifI[]>([])
const [showWindow, setShowWindow] = useState(false)
const fetchData = async () => {
try {
const data: notifI[] = await PushAPI.user.getFeeds({
user: `eip155:${chainId}:${account}`,
env: 'staging',
})
setNotification(data)
} catch (e) {
console.log(e)
}
}
useEffect(() => {
if (account) {
console.log('Calling user details')
fetchData()
}
}, [account])
我得到的错误
./node_modules/@ethereumjs/util/dist/asyncEventEmitter.js 24:41
Module parse failed: Unexpected token (24:41)
File was processed with these loaders:
* ./node_modules/react-scripts/node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| let [data, callback] = args;
| const self = this;
> let listeners = self._events[event] ?? [];
| // Optional data argument
| if (callback === undefined && typeof data === 'function') {
我真的是新的工作与这样的巨大的存储库,请帮助我,并提前感谢
1条答案
按热度按时间tsm1rwdh1#
在useEffect中移动/定义
fetchData
函数有关详细信息,请参阅:this blog