vue 转react尝试

2023-05-23,,

今天学习了一下react,感觉跟vue 语法类似。于是举一反三搜索了一下,发现由个工具,可以提供这样子的服务:

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

vue 和 react 的生命周期

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

react 没有 computeds

react 没有 computed, 需要支持 手动 setState

hooks 语法

hooks 下如何还原 setState 类似的操作:

可以使用 useReducer

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