According to docs state of react app has to be something serializable. What about classes then?
Let's say I have a ToDo app.
Each of Todo
items has properties like name
, date
etc. so far so good.
Now I want to have methods on objects which are non serializable. I.e. Todo.rename()
which would rename todo and do a lot of other stuff.
As far as I understand I can have function declared somewhere and do rename(Todo)
or perhaps pass that function via props this.props.rename(Todo)
to the component.
I have 2 problems with declaring .rename()
somewhere:
1) Where? In reducer? It would be hard to find all would be instance
methods somewhere in the reducers around the app.
2) Passing this function around. Really? should I manually pass it from all the higher level components via
And each time I have more methods add a ton of boilerplate to just pass it down?
Or always do and hope that I only ever have one rename method for one type of object. Not Todo.rename()
Task.rename()
and Event.rename()
That seems silly to me. Object should know what can be done to it and in which way. Is not it?
What I'm missing here?
Records
objects as mentioned in the documentation. But, by the way, you could totally pass a simple object with methods, they are serializable. – Goldstone