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

2020/07/27 react hooks初体验 #44

Open
ChenPt opened this issue Jul 27, 2020 · 0 comments
Open

2020/07/27 react hooks初体验 #44

ChenPt opened this issue Jul 27, 2020 · 0 comments

Comments

@ChenPt
Copy link
Owner

ChenPt commented Jul 27, 2020

React Hooks 初体验

Hooks能带来啥?

Hooks首先解决的问题就是

  1. React的Function组件无法使用state,且没有生命周期钩子。
    2.class组件,通用逻辑复用难度高,使用HOC封装通用逻辑的组件,DOM结构混乱,代码不直观

目前接触到了useState useRef useCallback useEffect
useState就是给函数式组件提供了state,和更新state的方法。

function useUserName(props) {
  const [name, setName] = useState('pt')
}

当调用setName方法更新name的时候,这个组件就会进行re-render

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

1 participant