修改代码热更新后组件状态不更新
coderlfm opened this issue · comments
修改代码热更新后点击按钮,状态不会更新,不清楚是什么原因
"dependencies": {
"@craco/craco": "^5.7.0",
"hox": "^1.1.2",
"node-sass": "^4.14.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.0",
"simple-progress-webpack-plugin": "^1.1.2",
"web-vitals": "^0.2.4"
},
import { useState } from 'react'
import { createModel } from 'hox'
function useToken() {
const [token, setToken] = useState('');
const changeToken = (payload) => setToken(payload.token);
return { token, changeToken }
}
export default createModel(useToken);
组件中
import React, { memo, useState } from 'react'
import useToken from './usetoken'
export default memo(function Home() {
const token = useToken();
const changeToken = () => token.changeToken({ token: '#123456abc' })
const clearToken = () => token.changeToken({ token: '' })
return (
<div>
<p>token: {token.token}</p>
<button onClick={changeToken}>设置token</button>
<button onClick={clearToken}>清空token</button>
</div>
)
})
同样遇到这个问题,有人看吗