react中的props
React组件层级
- 父组件把数据层传递给子组件渲染消费
- 子组件通过props中的callback,向父组件传递信息
- 将视图容器作为props进行渲染
React更新机制
- props 可以作为组件是否更新的重要准则,变化即更新( PureComponent ,memo )
React插槽
- React 可以把组件的闭合标签里的插槽,转化成 Children 属性
监听props改变
类组件 - unsafe_componentWillReceiveProps
1 | If you define UNSAFE_componentWillReceiveProps, React will call it when the component receives new props. It only exists for historical reasons and should not be used in any new code. Instead, use one of the alternatives |
函数组件 - useEffect
props children模式
prop + child
- props插槽组件 | render props模式 | 混合模式
- react-router (Switch, Route) - The
<Routes>
component recurses through itsprops.children
, strips their props, and generates an object like this - antd (Form , FormItem)
skills
- 抽象props
- 抽离props
- 注入props
- 隐式注入props