小编Nic*_*1R1的帖子

React - 将ref从哑组件(子组件)传递给智能组件(父组件)

我有一个智能和一个哑组件,我需要引用我的智能组件中的转储组件中的元素:我可以用道具传递它吗?

Dumb:
export default (props)=>{
return(
    <input type='number' ref='element'}/>
);}

Smart:
class Parent extends Component {
    constructor(props) {
        super(props);
    }
componentDidMount() {
    const node = this.refs.element; // undefined
    }
render(){
    return <Dumb { ...this.props }/>
    }
}
Run Code Online (Sandbox Code Playgroud)

ref reactjs redux

10
推荐指数
2
解决办法
2万
查看次数

标签 统计

reactjs ×1

redux ×1

ref ×1