If I wanted to follow FP principals should my inner functions be pure in this React Function Component? Or is it fine due to the nature of this component and the fact that it is a Function Component? (because, I'm probably incorrect in my technical description, that it's a type of closure. and therefore it needs to change and access the state.)
const Component = ({data, onChange}) => {
const [list, setList] = useState(data);
const removeItem = (id) => {
const newList = list.filter(item => item.id !== id);
setList(newList);
... do something else here onChange ...
}
return (
<>
{list.map(({text, id}) => (
<div onClick={() => removeItem(id) }>{text}</div>
))}
</>
)
}
Update
Specifically should I be concerned that removeItem reference list and setList which are not inputs to this function when I'm trying to apply functional programming principals.
setListyou're thinking of?listandsetListbeing referenced inside of that function.