-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor feeds to use react-query #1862
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm overall
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good to me. One smaller note: stale data flashes and is replaced when you toggle back and forth between feeds. We might want to play with staleTime, maybe even only manually marking as stale to trigger a refresh.
[opts?.disableTuner], | ||
) | ||
|
||
const pollLatest = useCallback(async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we shouldn't just do polling, hasNew
state, etc in this hook and expose as state 🤔 Would remove some logic from Feed
and make that simpler.
In general, I think we should aim for something as simple as:
- fetch data and handle refresh and state up top (like in this hook)
- all logic lives here
- construct item skeleton
- pass to FlatList to render
Maybe can't get to that point, or not right now anyway, but could be a good guiding light moving forward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's probably possible, though we do need the onHasNew
emitter so that we can emit that state back out to the wrapper components
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If outer components need state, could we move this hook up a level and flatten children out more? Then we don't need to emit anything, we just check for hasNew
and render stuff.
But yeah not saying we should do all this here 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to keep the hook inside the <Feed>
component but maybe the answer is to move that state and UI behaviors into the Feed component
Refactors the feed to use react-query.
The feed query-key is the
FeedDescriptor
type, which is a string that uses template-literal-types to ensure correct usage. I decided to go with a string because it gets passed around a fair amount and it'll be easier to avoid needless re-renders with that. Also note: it uses a pipe (|
) separator for the params to avoid colliding with potential values (initially I used:
but that collides with URIs).