javascript - React add new props to cloned element with spread operator -


i have container so:

const reactcontainer = ({ children, ...rest }) => react.cloneelement(children, rest); 

now, want add new props - count , flag - cloned elements:

so tried this:

const reactcontainer = ({ children, ...rest }) => {     const count = 0;     const flag = false;      return react.cloneelement(children, {count, flag}, rest); }; 

but doesn't work , i've tried other variations. how can add these new props cloned elements keeping spread operator simplicity?

please try this:

const reactcontainer = ({ children, ...rest }) => {     const count = 0;     const flag = false;      return react.cloneelement(children, {...rest, count, flag}); }; 

please note in above example ...rest used in component function definition acts rest parameters syntax while in cloneelement acts spread syntax.


Comments

Popular posts from this blog

Ansible warning on jinja2 braces on when -

Parsing a protocol message from Go by Java -

node.js - Node js - Trying to send POST request, but it is not loading javascript content -