How to add function in JSX?

1) You’re missing a closing bracket on the ReactDOM line: ReactDOM.render(<Main />, document.getElementById(‘root’)); 2) You need to call the function for it to work vanilla_JS() In this working example instead of logging to the console I’m returning a string: function Main() { const vanilla_JS = function() { return ‘testing’; } return ( <main> <div>{vanilla_JS()}</div> </main> … Read more

Build an HTML table using React from arrays [closed]

You can create your table using Table function and EachRow function. var headers=[‘heading1′,’heading2’]; var values=[[‘1′,’2’],[‘3′,’4’]]; var Table = (props) => { return ( <table className=”table”> <thead> <tr> {props.headers.map(header => <th>{header}</th>)} </tr> </thead> <tbody> {props.values.map(row => <EachRow row={row} />)} </tbody> </table> ); }; var EachRow = (props) => { return ( <tr> {props.row.map(val => <td>{val}</td>)} </tr> … Read more

Remove duplicate from array within array

You can check if an element exists prior to using push. Lots of ways to approach this, but an easy solution might be: Array.prototype.pushUnique = function pushUnique(item) { if (this.indexOf(item) === -1) { this.push(item); } } // Then use it… const arr = []; arr.pushUnique(“Family Practice”); // arr = [“Family Practice”] arr.pushUnique(“General Practice”); // arr … Read more