
React
柴狗狗
这个作者很懒,什么都没留下…
展开
-
React给children传props
如下可以将 id = 1 作为 props 传入每个子组件中,注意要使用返回值作为新的 children,原来的 children 并没有发生改变React.Children.map(this.props.children, child => { return React.cloneElement(child, { id: 1, });})详细示例如下import React, { PureComponent } from 'react';export d原创 2021-08-16 17:06:56 · 3572 阅读 · 0 评论 -
React父组件调用子组件方法
import React, {Component} from 'react';export default class Parent extends Component { onRef = ref => { this.childRef = ref } click = () => { this.childRef.sayHello() } render() { return (原创 2021-08-16 17:04:41 · 634 阅读 · 0 评论