by benmmurphy · 7y ago · 0 comments
the example would become something like:
const nameNamespace = [Symbol()];
const surnameNamespace = [Symbol()];
const name = useFormInput(nameNamespace);
const surname = useFormInput(surnameNamespace);
const valueKey = Symbol();
function useFormInput(namespace) {
const [value, setValue] = useState(extendNamespace(namespace, valueKey));
return {
value,
onChange(e) {
setValue(e.target.value);
},
};
}
there are a lot of drawbacks with doing it like this tho. like it is much less performant because you are creating all these arrays and having to do these comparisons across possibly big chains of symbols. also, there doesn't seem to be any way to easily store these chains in a map like structure for fast lookup except for using nested maps which is a bit weird.