vue turn react attempt

Today, I am learning a bit react, I felt vue-like syntax. So giving top priority to search a bit, discovered by a tool that can provide a service like this:

https://tools.w3cub.com/vue-to-react

vue and react life cycle

created: 'componentWillMount',
mounted: 'componentDidMount',
updated: 'componentDidUpdate',
beforeDestroy: 'componentWillUnmount',
errorCaptured: 'componentDidCatch',
render: 'render'

react no computeds

react not computed, the need to support manual setState

hooks grammar

How to restore the lower hooks setState something like:

You can use useReducer

const [state, setState] = useReducer(
    (state, action) => {
      return {
        ...state,
        ...action
      };
    },{ name: '小熊猫',category: '小熊猫科' })
setState({ name: '金鱼' })

Guess you like

Origin blog.51cto.com/xp114/2429447