Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改代码热更新后组件状态不更新 #56

Open
coderlfm opened this issue Nov 21, 2020 · 1 comment
Open

修改代码热更新后组件状态不更新 #56

coderlfm opened this issue Nov 21, 2020 · 1 comment

Comments

@coderlfm
Copy link

修改代码热更新后点击按钮,状态不会更新,不清楚是什么原因

  "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>
    )
})
@ihoment-chentao
Copy link

同样遇到这个问题,有人看吗

@awmleer awmleer mentioned this issue May 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants