-
Notifications
You must be signed in to change notification settings - Fork 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
@uppy/react: add useUppyState #4711
Conversation
Updated dependencies detected. Learn more about Socket for GitHub ↗︎
|
As for the future work planned: what do you think about offering an |
I thought about it but refrained from doing so:
Their use cases for adding context also don't align with what Uppy is used for. Realistically, there is only one page where people upload in most apps and it would be overkill to provide a context for this in my opinion. I'd rather keep it simple and explicit for now. Perhaps reconsidering when we see people needing this more. |
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.
simple and elegant!
lgtm except for comments by others
* main: Bucket fn also remote files (#4693) fixup! Added Companion OAuth Key type (#4668) Added Companion OAuth Key type (#4668) meta: check for formatting in CI (#4714) meta: bump get-func-name from 2.0.0 to 2.0.2 (#4709) meta: run Prettier on existing files (#4713) Release: [email protected] (#4716) meta: add Prettier (#4707) @uppy/aws-s3-multipart: retry signature request (#4691)
Maybe a noob question: why does |
|
@aduh95 still getting the same error as before when running |
* main: @uppy/vue: export FileInput (#4736) examples: update `server.py` (#4732) @uppy/aws-s3-multipart: fix `uploadURL` when using `PUT` (#4701) @uppy/dashboard: auto discover and install plugins without target (#4343) e2e: upgrade Cypress (#4731) @uppy/core: mark the package as side-effect free (#4730) Bump postcss from 8.4.16 to 8.4.31 (#4723) meta: test with the latest versions of Node.js (#4729)
…into new-react-hook * 'new-react-hook' of https://github.com/transloadit/uppy: Revert unrelated change save react at the top level to workaround
This is now resolved 👍 |
* main: More image editor improvements (#4676) @uppy/react: add useUppyState (#4711) Release: [email protected] (#4760) Bump jsonwebtoken from 8.5.1 to 9.0.0 in /packages/@uppy/companion (#4751) Bump react-devtools-core from 4.25.0 to 4.28.4 (#4756) Bump webpack from 5.74.0 to 5.88.2 (#4740) Bump @babel/traverse from 7.22.5 to 7.23.2 (#4739) @uppy/core: fix `sideEffects` declaration (#4759) Release: [email protected] (#4754) @uppy/aws-s3-multipart: fix `TypeError` (#4748) Bump tough-cookie from 4.1.2 to 4.1.3 (#4750) example: simplify code by using built-in `throwIfAborted` (#4749) @uppy/aws-s3-multipart: pass `signal` as separate arg for backward compat (#4746) meta: fix TS integration (#4741)
@Murderlon I just notice that For example There is another api from react use-sync-external-store package, which is BTW, it this api released? I tried to import from |
| Package | Version | Package | Version | | ---------------------- | ------- | ---------------------- | ------- | | @uppy/aws-s3 | 3.5.0 | @uppy/provider-views | 3.7.0 | | @uppy/aws-s3-multipart | 3.9.0 | @uppy/react | 3.2.0 | | @uppy/companion | 4.11.0 | @uppy/transloadit | 3.4.0 | | @uppy/companion-client | 3.6.0 | @uppy/tus | 3.4.0 | | @uppy/core | 3.7.0 | @uppy/url | 3.4.0 | | @uppy/dashboard | 3.7.0 | @uppy/utils | 5.6.0 | | @uppy/image-editor | 2.3.0 | @uppy/xhr-upload | 3.5.0 | | @uppy/locales | 3.4.0 | uppy | 3.19.0 | - @uppy/dashboard: Remove uppy-Dashboard-isFixed when uppy.close() is invoked (Artur Paikin / #4775) - @uppy/core,@uppy/dashboard: don't cancel all files when clicking "done" (Mikael Finstad / #4771) - @uppy/utils: refactor to TS (Antoine du Hamel / #4699) - @uppy/locales: locales: add ca_ES (ordago / #4772) - @uppy/companion: Companion+client stability fixes, error handling and retry (Mikael Finstad / #4734) - @uppy/companion: add getBucket metadata argument (Mikael Finstad / #4770) - @uppy/core: simplify types with class generic (JokcyLou / #4761) - @uppy/image-editor: More image editor improvements (Evgenia Karunus / #4676) - @uppy/react: add useUppyState (Merlijn Vos / #4711)
Thanks for the update. I can't find anything about |
@Murderlon react-redux use this hook, you can see the code here https://github.com/reduxjs/react-redux/blob/854f3e1687382925952712399f93c0e7d271cdbb/src/utils/useSyncExternalStore.ts#L2C94-L2C94 . And this hook is published by react offical repo, https://github.com/facebook/react/blob/main/packages/use-sync-external-store/src/useSyncExternalStoreWithSelector.js.
Yes if we implement this way, but the recommend usage of |
| Package | Version | Package | Version | | ------------------ | ------- | ------------------ | ------- | | @uppy/core | 3.7.1 | @uppy/react-native | 0.5.2 | | @uppy/dashboard | 3.7.1 | uppy | 3.19.1 | | @uppy/react | 3.2.1 | | | - @uppy/react: Revert "@uppy/react: add useUppyState (#4711)" (Artur Paikin / #4789) - @uppy/dashboard: fix(@uppy/dashboard): fix wrong option type in index.d.ts (dzcpy / #4788) - meta: fix build of TypeScript plugins (Antoine du Hamel / #4784) - @uppy/core,@uppy/dashboard,@uppy/react-native: Update Uppy's blue color to meet WCAG contrast requirements (Alexander Zaytsev / #4777) - meta: fix JS2TS script (Antoine du Hamel / #4778)
Closes #4698
Closes #4680
Closes #4725
Problems
This PR focusses on one but outlines all problems to see how they relate to each other. Normally it's better to only talk about one thing in a PR, but I thought I proof of concept would help the discussion and it's good to talk about how the problems and solutions relate to each other. So feel free to provide feedback on all three.
Solution to 1 (this PR)
A new hook
useUppyState
which allows you to select a part of Uppy's state and the component will only re-render based on that state. This is mostly useful if you want to create a custom UI or if you use something like Dashboard but you just want to do something extra on the page somewhere based on Uppy state.Solution to 2 and 3 (future docs PR)
If you pass a function to
useState
, React will only call it during initialization. When re-rendering, the@uppy/default-store
state remains in the background so uploads will continue. When the component is unmounted, its state (and uploads) will be reset.Component based thinking means that you isolate state with your component. People writing React want to do this with Uppy. In fact, if you want to render an unknown amount of Uppy components, this is the only way.
Example: I want Uppy state to remain during re-renders but not during page change (unmount)
Example: I want Uppy state to also remain during page changes
It's a common use case from customers, they want they're users to able to use their app (switch pages) while the upload continues. This is not something we can easily provide in a hook or store, unless we want to store everything in localStorage (not a good idea). However using React patterns this is possible: lifting state up.