How to update multiple state properties with React hooks

Issue #655

Declare state and setState

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
export default function Showcase(props) {
const factory = props.factory
const [state, setState] = useState(
{
factory,
selectedFilter: { name: '' }
}
)

const onFilterClick = (filter) => {
setState({
selectedFilter: filter,
factory: factory.filter((app) => {
return app.showcase.platforms.includes(filter.name)
})
})
}

let cards = state.factory.map((app, index) => {
return (
<Card app={app} key={app.slug} />
)
})

return (
<div>
<FilterBar onClick={onFilterClick} />
<div css={css`
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: flex-start;
margin: 0 auto;
padding: 0 8vw;
`}>
{cards}
</div>
</div>

)
}

Comments