diff --git a/snippets/mapped-table.md b/snippets/mapped-table.md new file mode 100644 index 000000000..6bb78a2e7 --- /dev/null +++ b/snippets/mapped-table.md @@ -0,0 +1,35 @@ +### MappedTable + +Generate a table with dynamic rows based on passed array of data. Optionally include headers. + +Conditionaly check weather to include table headers or not. Use `Array.prototype.map` to map over array of data and return `` for each entry. + +```jsx +function MappedTable(props) { + return ( + + {props.headers ? return({props.headers.map((h, i)=> (h))}) : return null} + {props.data.map((v, i) => { + return ( + + v.name + + ); + })} + + ); +} +``` + +```jsx +const people = [{ id: 841, name: 'John' }, { id: 241, name: 'Jesse' }]; +const headers = ['id', 'name']; +ReactDOM.render( + , + document.getElementById('root') +); +``` + + + +