項目中我一般用的還是react15的比較多,偶爾接觸react16,目前使用的大多是生命周期的區別,16新增了幾個生命周期。
static getDerivedStateFromProps:用於代替componentReceiveProps。是個靜態方法。
父組件傳入子組件的屬性更新時,同步更新子組件state。
B的a屬性值是state,會變化
新值和舊值不同時,返回新值更新state,否則返回null不更新。
UNSAFE_componentWillMount:用於代替componentWillMount,但還是不建議使用。
componentDidCatch:組件報錯時的處理函數,一般用不到。