Accessing React component children props from the parent

前端 未结 4 1312
野的像风
野的像风 2021-01-07 16:36

I am currently in the process of designing the interface for a game engine that is written in JavaScript and ReactJS.

If a game object has a texture, the source of t

4条回答
  •  南方客
    南方客 (楼主)
    2021-01-07 17:36

    You should be able to just do this.props.texture.props. I'm not ware of it being an anti-pattern, but I don't think it's a common pattern either. It certainly looks like it may be breaking encapsulation if you want to access a specific prop.

    You don't have to pass the element as prop to get a reference to it. You can access children via this.props.children.

    See the documentation for more info.

提交回复
热议问题