javascript - React - passing props to a component recieved in props -


i'm using react , faced problem.

i have component needs accept component prop, , pass same component other props. example:

export default class item extends react.component {     render() {         return (<div onclick={this.props.onclick}>some content.</div>)     } }  item.proptypes = {     onclick: proptypes.func.isrequired }  export default class container extends react.component {     onclick() {         // something.     }     render() {         // render here item , passing onclick method.     } }  container.proptypes = {     item: proptypes.element.isrequired } 

edit: can use es5 syntax , this:

react.createelement(item, {     onclick: this.onclick }); 

but how can achieve in es6?

this need do, if need pass props, can use spread operator too.

export default class item extends react.component {   render() {     return (       <div onclick={this.props.handleclick}>some content.>       </div>       )   } }  item.proptypes = {   onclick: proptypes.func.isrequired }  export default class container extends react.component {    render() {     const handleclick = () => {       // something.     }     // render here item , passing onclick method.     render () {       return (         <item handleclick={handleclick} />       );     }   } }  container.proptypes = {   item: proptypes.element.isrequired } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -