Hey team,
I've been playing with Recoil and love it so far. One thing that could confuse some people / editors is using default as the key for the.. default state of an atom.
As we know, default is a JavaScript keyword since ES Modules export default xxx. I believe it's also the reason why React uses className instead of class and the HTML spec htmlFor instead of for.
Are there any plans to change default to an alternative word, that is not a reserved JavaScript keyword (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar)? Or do we keep the current word as it does describe what it's intended to be pretty accurately.
Kind regards
I'd much prefer not using an object at all
atom(key, default)
There's evidence of additional options in baseAtom but these look like very specific alternative uses so it makes more sense for them to be an options object
atom(key, default, { persistence, dangerouslyAllowMutability })
It's not a problem to use JS reserved words as JS object keys. This doesn't confuse the parser. class is already an HTML element attribute for CSS styles, so there was a naming conflict.
How the options are provided really comes down to aesthetics and personal preference. We won't be able to please everyone. After discussion we ended up with an object of named properties for atom and selector functions. This seemed a bit cleaner than mixing positional and named arguments, provided greater flexibility for adjusting the set of options over time, and was more explicit to make call-sites more self-explanatory, particularly as we look at consistency with selector options. Of course, there are pros/cons for different styles.
Most helpful comment
I'd much prefer not using an object at all
There's evidence of additional options in baseAtom but these look like very specific alternative uses so it makes more sense for them to be an options object