hiii everybody,
i'm new in react and i have lost my day at Trying to run my code
i have a dictionnary in a JS : {key, value}.
i want create some button with the name equal the key. i think i I think I need to pass my dictionary ( or an array of key, because i dont need the value associed) to my reactDom.render .
i have create this :
class ButtonList extends React.Component {
onClick(event) {
clictodraw("name");
}
render() {
let items = this.props.items || []
let rows = items.map(
item => {return (
<button onClick={this.onClick}>{item}</button>);}
);
return (
{rows}
);
}
}
window.shareRenderFunc5 = function (tab) {
ReactDOM.render(
<ButtonList items={tab}/>,
document.getElementById('app')
);
}
but he give me this message :
Error: ButtonList.render(): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.
i think my problem is on the Data input to props. if you know what is the problem, please tell me.
thanks for your help
return ( <div> {rows} <.div> );wrap the rows with div because rows will be an array and we can't return more than one children.maparray elements to components, you need to give each one a uniquekeyprop (e.g. their index in the array)