[Request] Expose `setValue` method from `useClipboard` hook
See original GitHub issueDescription
Please expose a new setValue
method from the hook so users can update the value the onCopy
method will copy to the user’s clipboard
Problem Statement/Justification
There are frequently times where a page has multiple components that can all be copied to a clipboard. The useClipboard
hook doesn’t expose a way to change that value and, as a result, the dev is forced to rely on a re-render to execute for a useState
value to update before the clipboard will work OR the dev will need to abstract the copy-able value into a new component so multiple hooks can exist on one page.
Proposed Solution or API
const defaultValue = 'some string';
const { onCopy, setValue } = useClipboard(defaultValue);
// ...
const updatedValue = 'some new string';
setValue(updatedValue);
onCopy();
// updatedValue copied to clipboard
Alternatives
Moving all relevant copy-able elements to their own components (ideal from an abstraction standpoint, but often unnecessary if the original file is trivially small)
Additional Information
No response
Issue Analytics
- State:
- Created a year ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
useForm - setValue - React Hook Form
This function allows you to dynamically set the value of a registered field and have the options to validate and update the form...
Read more >useSlider – React Aria - React Spectrum Libraries
Documentation for useSlider in the React Aria package.
Read more >useControllableState - Chakra UI
The useControllableState hook returns the state and function that updates the state, ... const [value, setValue] = useControllableState(options).
Read more >Macro Express 5 Manual of Instruction
If you want to have the macro paste the text into your application via the. Windows clipboard, select the Use Clipboard to Paste...
Read more >https://opensource.apple.com/source/WebKit/WebKit-...
WebCoreSupport/ChromeClientGtk.cpp: Use the new helper method from GtkUtilities. ... (webkit_hit_test_result_init): call C++ ctors in private data.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I ended up doing this to fix it on every part of the app we use
useClipboard
:Leaving this for future reference but seems a bit redundant having to always do this.
This is an extremely confusing api for a hook. If a hook takes a value, it should react to changes in that value, not require calling a separate function to update it. This was also a breaking change despite what https://github.com/chakra-ui/chakra-ui/pull/6763 says.