How to handle local state when using relay?

Short answer: It depends, I prefer #2 solution

1. Why I prefer #2

Solution #2 is an advanced version of solution #1, so #1 is passed. But #1 of course has it’s case, most old sites do that.

Solution #3 will keep the server busy, that will either raise your cost for server or slow down user experience when your business scales, so #3 is passed. But as an internal system or some business meant to be used by less user, #3 become good choice.

If the user accidentally closes the browser

Solution #2 still can use an interval to sync it’s content to server, surely you’ve seen auto save in xx seconds many times. Or you can use localstorage, it will not save cross computer, but it will save every bit of your change, even every history with zero sync lag.

2. It is not anti-pattern

Syncing between local state and relay props might be a source for bugs

I should say this is not only happen for #2, if some other change the article at the same time

For #1, your modification will be overwritten, and you can never find a clue where your modifications gone

For #3, your content is changing all the time, can you still work on it?

So if there is such case, you need to add version control logic right? If no such case, your local state is single truth.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)