I'd like to store a reference to a class in state but an error occurs.
Specifically, the following:
useState(SomeClass)
results in:
Class constructor SomeClass cannot be invoked without 'new'
...
I can find another route for my specific need but I'd like to understand what the issue is here exactly.
--
FWIW here's a concrete situation where the above would be useful:
Consider a component that displays a list of Super[] but filtered by subclass. The component contains a set of radio buttons to set the filtering. e.g.
const FilterableListView = (props:{items:SuperType[]})=>{
const [SelectedType,setType] = useState(DefaultType as SuperType)// where DefaultType extends SuperType
const itemsToDisplay = props.items.filter(item=>item instanceof SelectedType)
// in radio button callback somewhere...
setType(SomeOtherSubType)
...
}
Here the state is the filtering criteria. No need for instances of any of the class references.
Again, I can skin this cat in many ways — I just would like to know why useState(Class) results an attempt to instantiate Class.