Skip to content
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

[useClipboard] Allow imperative usage #7754

Closed
kristian240 opened this issue Jun 12, 2023 · 1 comment · Fixed by chakra-ui/chakra-ui-docs#1603 · May be fixed by #7761
Closed

[useClipboard] Allow imperative usage #7754

kristian240 opened this issue Jun 12, 2023 · 1 comment · Fixed by chakra-ui/chakra-ui-docs#1603 · May be fixed by #7761
Labels
needs triage Issues and pull requests that need triage attention

Comments

@kristian240
Copy link
Contributor

Description

I need to copy a current URL from a browser using a SSR app.

Problem Statement/Justification

The problem is that I cannot use

const clipboard = useClipboard(window.location.toString());

since the window is undefined on the server side.

Because of that, I need to use an extra useEffect to notify that I'm on the client and then update the state. Notice that typeof window === "undefined" ? "" : window.location.toString() is no-go since you might render the value on page so it is not sustainable.

Proposed Solution or API

The solution would be to allow imperative usage

const clipboard = useClipboard();

return <button onClick={() => clipboard.onCopy(window.location.toString())}>Copy URL</button>

Alternatives

No response

Additional Information

In my head, this is not a breaking change, but I might be wrong. Also, I would like to work on PR for this if you folks think it is okay to add it to Chakra UI.

@kristian240 kristian240 added the needs triage Issues and pull requests that need triage attention label Jun 12, 2023
@segunadebayo
Copy link
Member

Hi @kristian240,

Please go ahead and make a PR for this. Sounds like a useful addition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issues and pull requests that need triage attention
Projects
None yet
2 participants