Renders a list of elements from an array of primitives.
isOrdered
prop to conditionally render an <ol>
or a <ul>
list.Array.prototype.map()
to render every item in data
as a <li>
element with an appropriate key
.const DataList = ({ isOrdered = false, data }) => {
const list = data.map((val, i) => <li key={`${i}_${val}`}>{val}</li>);
return isOrdered ? <ol>{list}</ol> : <ul>{list}</ul>;
};
const names = ['John', 'Paul', 'Mary'];
ReactDOM.render(<DataList data={names} />, document.getElementById('root'));
ReactDOM.render(
<DataList data={names} isOrdered />,
document.getElementById('root')
);
React, Components
Renders a table with rows dynamically created from an array of primitives.
React, Components
Renders a table with rows dynamically created from an array of objects and a list of property names.
React, Components
Renders a checkbox list that uses a callback function to pass its selected value/values to the parent component.