Replies: 1 comment 2 replies
-
Hey @joprice. It is indeed a feature. Zedux inherited it, along with its problems, from Recoil. Lots of people complained about that part of Recoil and it's probably the main reason Jotai became popular. It's something we definitely don't want to change because it facilitates cross-realm state sharing. Predictable string keys/ids are the reason Zedux is more capable than Jotai when multiple windows, SSR, or web workers are involved. I also turned it into a Dependency Injection feature. Learning from React QueryOther tools like Storybook and React Query have the same problem. They're just as vulnerable to copy-paste. But there is something we can learn from React Query: It's less vulnerable to other accidental duplication since their model naturally namespaces query keys based on API endpoints. I think I'm going to recommend a similar practice in the Zedux best practices guide. Namespace atom keys by feature - e.g. But again, this won't help with copy-paste. Here are some things that will: The
|
Beta Was this translation helpful? Give feedback.
-
I just hit a bug where I duplicated an atom and renamed it's binding
const a -> const b
, but didn't change it's name, and was surprised to find that it didn't fail at runtime. For instance, defining these atoms with duplicated key:I have a feeling this is a feature, as I saw in the docs that you can override atoms, e.g. for testing purposes. I think I even made use of it at one point already, but I'm curious if there could be a strict mode where duplicate atom registration fails, since I would imagine in most cases, atom names are meant to be distinct.
I'm also curious about the expected behavior in the meantime, since I think what I'm seeing is the first one registered taking precedence. If that's the case, then it's not overriding, but ignoring duplicate registrations, so seems easier to introduce a strict mode that rejects the second call in that case.
Beta Was this translation helpful? Give feedback.
All reactions