An open API service indexing awesome lists of open source software.

https://github.com/jusexton/react-table-practice


https://github.com/jusexton/react-table-practice

Last synced: about 1 year ago
JSON representation

Awesome Lists containing this project

README

          

# React Table Practice

## Simple Example

```jsx
const people = [
{
firstName: "Justin",
lastName: "Sexton",
},
{
firstName: "Foo",
lastName: "Bar",
},
{
firstName: "Baz",
lastName: "Bob",
},
];

const headers = ["First Name", "Last Name"];

const App = () => {
return (
<>



{headers.map((header, index) => {
return {header};
})}



{people.map((person, index) => {
return (

{person.firstName}
{person.lastName}

);
})}


>
);
};
```

## Example With Checkbox Selection

```jsx
const people = [
{
firstName: "Justin",
lastName: "Sexton",
},
{
firstName: "Foo",
lastName: "Bar",
},
{
firstName: "Baz",
lastName: "Bob",
},
];

const headers = ["First Name", "Last Name"];

const App = () => {
const selectedValues = useRef({});
const { isToggled: allValuesSelected, toggle: toggleAll } = useToggle();

const toggleSingle = (selected, { firstName, lastName }) => {
const key = `${firstName}${lastName}`;
selectedValues.current = {
...selectedValues.current,
[key]: allValuesSelected || selected,
};
};

return (
<>



{headers.map((header, index) => {
return {header};
})}



{people.map((person, index) => {
return (
toggleSingle(selected, person)}
>
{person.firstName}
{person.lastName}

);
})}


>
);
};
```