-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
compose: Add types useAsyncList #31523
Conversation
Size Change: +581 B (0%) Total Size: 1.31 MB
ℹ️ View Unchanged
|
const [ current, dispatch ] = useReducer( | ||
listReducer as Reducer< T[], ResetAction< T > | AppendAction< T > >, | ||
[] as T[] | ||
); |
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.
Remember the Redux ducks pattern we discussed few days ago? We could use something similar in this hook:
const [ current, setCurrent ] = useState< T[] >( [] );
setCurrent( firstItems ); // replacement for reset action
setCurrent( state => [ ...state, item ] ); // replacement for append action
That saves a lot of effort typing the reducer and the actions. Many lines of code can be deleted.
@youknowriad what's the best way to test changes to |
Just check that the patterns list in the inserter is performant enough. In Safari you'll notice that things appear more slowly but at least it doesn't freeze tab switching. |
Try also switching patterns categories back and forth and see that there are no missing patterns or things like that. |
Thanks Riad! It seems to work fine for me. @jsnajdr do you want to verify as well and then review the changes? |
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 tested the new version on a tiny toy app (that renders an async list) and verified that it works exactly the same way as the previous one.
Description
Adds types to
useAsyncList
. This also simplifies the logic inside ofuseAsyncList
to useuseState
instead ofuseReducer
. This removes about a dozen lines of code.Are there unit tests for this function?
How has this been tested?
Type checks and unit tests continue to pass.
Types of changes
Non-breaking changes.
Checklist:
*.native.js
files for terms that need renaming or removal).