30 seconds of React

Array

Click on a snippet's name to view its code.

DataList

Renders a list of elements from an array of primitives.

  • Use the value of the isOrdered prop to conditionally render a <ol> or <ul> list.
  • Use Array.prototype.map to render every item in data as a <li> element, give it a key produced from the concatenation of the its index and value.
  • Omit the isOrdered prop to render a <ul> list by default.

DataTable

Renders a table with rows dynamically created from an array of primitives.

  • Render a <table> element with two columns (ID and Value).
  • Use Array.prototype.map to render every item in data as a <tr> element, consisting of its index and value, give it a key produced from the concatenation of the two.

MappedTable

Renders a table with rows dynamically created from an array of objects and a list of property names.

  • Use Object.keys(), Array.prototype.filter(), Array.prototype.includes() and Array.prototype.reduce() to produce a filteredData array, containing all objects with the keys specified in propertyNames.
  • Render a <table> element with a set of columns equal to the amount of values in propertyNames.
  • Use Array.prototype.map to render each value in the propertyNames array as a <th> element.
  • Use Array.prototype.map to render each object in the filteredData array as a <tr> element, containing a <td> for each key in the object.

This component does not work with nested objects and will break if there are nested objects inside any of the properties specified in propertyNames