I have a React
component:
const ProjectFamiliesFilterInput = React.memo(({ familyOptions, analysisGroupOptions, projectAnalysisGroupsByGuid, value, onChange, ...props }) => {
const allFamiliesSelected = !value.familyGuids || value.familyGuids.length === familyOptions.length
...
...
return (
<Form.Group inline widths="equal">
<BooleanCheckbox
{...props}
value={allFamiliesSelected}
onChange={selectAllFamilies}
width={5}
label="Include All Families"
/>
</Form.Group>
)
})
I want allFamiliesSelected
to be set upon first mount depending on whether value.familyGuids.length > 0
. How to achieve that with react hooks?
Clarification:
allFamiliesSelected = value.familyGuids.length === 0
- needs to be done on the first mount, but allFamiliesSelected = !value.familyGuids || value.familyGuids.length === familyOptions.length
- on subsequent updates and not on the first mount.