Replies: 6 comments 1 reply
-
It would be illegal usage of hooks, based on React's rules, to use hooks outside of rendering in a callback like that. |
Beta Was this translation helpful? Give feedback.
-
It's still against naming conventions and lint rules. |
Beta Was this translation helpful? Give feedback.
-
Sounds reasonable. But we can still use another naming convention to avoid nested closures. selector('some controller', () => {
const store = getCurrentStore()
const callback = getCallback(async () => {
await fetch()
store.set(/* ... */)
})
}) I believe this would be much cleaner |
Beta Was this translation helpful? Give feedback.
-
There are nuances here. For example, we actually implemented an approach like this where we could get an object with an interface that matched the hooks. The issues came when we think about the semantics of subscriptions. Using the methods during rendering would add subscriptions for consistency and to avoid mysterious inconsistencies for users. That was actually convenient in some cases, but meant we had to track dynamic number of subscriptions. When working with the latest React API for subscriptions that are safe with concurrent rendering the hooks don't lend themselves for a dynamic count of subscriptions. There are similar complications with subscriptions for an exposed store as well. What use case are you trying to unblock with exposing the store directly? |
Beta Was this translation helpful? Give feedback.
-
Thanks. I understand the issue. import { getRecoilValue } from "recoil"
import { queryAtom } from "recoil-relay/apollo"
queryAtom({
key: "my-query",
query: "",
getVariables() {
return {
foo: getRecoilValue(somAtom)
}
}
}) this could avoid many confusing nested closures |
Beta Was this translation helpful? Give feedback.
-
Things like getRecoilValue may not be a good idea for async scenarios, so I thought the store object should be exported. const callback = getCallback(callbackInterface => {
return () => {
// ...
}
}) vs const callback = getCallback(() => {
const callbackInterface = getRecoilInterface();
})
const transationCallback = getTranstionCallback(() => {
getTranstion()
}) |
Beta Was this translation helpful? Give feedback.
-
similar for selector:
Beta Was this translation helpful? Give feedback.
All reactions