I have a screen A, a component B and a hook C.
The screen A renders the component B and executes its logic via the hook C.
Currently, in B I am rendering a list of pressable items:
function FilmCategoriesFilter({ // This is the component B
defaultSelectedFilter = FILM_CATEGORIES[0],
}) {
const [selectedFilter, setSelectedFilter] = useState(FILM_CATEGORIES);
return (
<PressableList
data={FILM_CATEGORIES}
selectedItem={selectedFilter}
onPressItem={setSelectedFilter}
/>
);
}
In my hook C I need to receive a param category, which has to be the same as the B's state value.
I have thought to move the state from the component to the parent, and update it via callback. But, if I do it, I think the component B will not be reusable any more.
I mean, if I handle its state, the data which makes it work, outside of it, the component will pass from being a self-functional component to just a UI component which only works in the screen A.
Is this an anti-pattern? Any tips?