React assembly Cloning - React.cloneElement (subassembly can be used to modify the attribute values, copy subassembly, the subassembly is added)

Project-level permissions required to achieve a button, it simply is the need to control what the front page action buttons need to be rendered by the background data binding, which does not require the rendering operation buttons,

The general plan is:

In the button labels to the original one and then sets the tag access control buttons, and each button control specific background given unique values ​​passed to the "access control button" component, then determines whether the button should not render the assembly , a technology used in point is React.cloneElement, you can modify the attribute values ​​of sub-elements, along with a look at the following React.cloneElement

 

React.cloneElement

参数:TYPE(ReactElement),[PROPS(object)] ,[CHILDREN(ReactElement)]

Cloning and returns a new ReactElement (internal sub-elements will follow cloning), new elements will return to retain elements of the old props, ref, key, will integrate new props (as long as the second parameter definitions) the new sub-element of the third parameter is added.

 

Note that the first parameter must be a string or createElement ReactClass, and in cloneElement in the first argument should be ReactElement:

 

Original Address: https://zhirongyuan.github.io/blog/2017/03/10/Blog-entry-two.html

Guess you like

Origin www.cnblogs.com/itgezhu/p/11576652.html