You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a number of instances where we modify the children of a component before we render the children. This allows us to add props to those children or at times conditionally render children.
This issue I'm noticing is that modifying the props of children is handled differently if the child is a metal component or an html element.
When I modify the props of a child that is an html element the props are appropriately applied to the dom. When I modify the props of a child that is a metal component, that component instance does not show those props existing.
On the other hand if I modify the config of a child that is an html element, the attributes passed as config are not rendered in the dom. And when I modify the config of a child that is a metal component, that component instance does the attributes passed through config on this.props.
The example below displays this issue:
The click event can only be passed to a child if it is passed as the props of an html element, or as the config of a metal component.
importComponent,{Config}from'metal-jsx';conststyles={cursor: 'pointer',padding: '20px'};classMetalComponentextendsComponent{render(){const{children, ...other}=this.props;return<div{...other}>{this.props.children}</div>;}}classClickComponentextendsComponent{created(){this.handleClick_=this.handleClick_.bind(this);}handleClick_(){console.log('handleClick_',this.props.objectKey);}render(){const{children, objectKey}=this.props;consttrigger=children[0];trigger[objectKey]={
...trigger[objectKey],onClick: this.handleClick_};return<divstyle={styles}>{trigger}</div>;}}ClickComponent.PROPS={objectKey: Config.string()};classTestextendsComponent{render(){return(<div><ClickComponentobjectKey="props"><div>{'onClick div, pass through props'}</div></ClickComponent><ClickComponentobjectKey="config"><div>{'onClick div, pass through config'}</div></ClickComponent><ClickComponentobjectKey="props"><MetalComponent>{'onClick metal component, pass through props'}</MetalComponent></ClickComponent><ClickComponentobjectKey="config"><MetalComponent>{'onClick metal component, pass through config'}</MetalComponent></ClickComponent></div>);}}Test.STATE={};exportdefaultTest;
Thanks.
The text was updated successfully, but these errors were encountered:
You're right, there were a few places that were still using the config object instead of the new props one, so if you manually reset props this wouldn't work. The main object should be props.
We'll later add a utility function for changing a child's props, so that you don't need to manually change them like this. This function will also help make sure that both config and props are changed every time, so that they can both be used with no data consistency problem.
We have a number of instances where we modify the children of a component before we render the children. This allows us to add
props
to those children or at times conditionally render children.This issue I'm noticing is that modifying the
props
of children is handled differently if the child is a metal component or an html element.When I modify the
props
of a child that is an html element theprops
are appropriately applied to the dom. When I modify theprops
of a child that is a metal component, that component instance does not show thoseprops
existing.On the other hand if I modify the
config
of a child that is an html element, the attributes passed asconfig
are not rendered in the dom. And when I modify theconfig
of a child that is a metal component, that component instance does the attributes passed throughconfig
onthis.props
.The example below displays this issue:
The click event can only be passed to a child if it is passed as the
props
of an html element, or as theconfig
of a metal component.Thanks.
The text was updated successfully, but these errors were encountered: