vue 轉react嘗試

今天學習了一下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: '金魚' })
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章