码迷,mamicode.com
首页 > 其他好文 > 详细

vue 转react尝试

时间:2019-08-14 14:58:02      阅读:66      评论:0      收藏:0      [点我收藏+]

标签:str   lan   update   ons   compute   需要   学习   turn   date   

今天学习了一下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: ‘金鱼‘ })

vue 转react尝试

标签:str   lan   update   ons   compute   需要   学习   turn   date   

原文地址:https://blog.51cto.com/xp114/2429447

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!