Implsible to use @reach/alert with React Context
See original GitHub issueš Bug report
Current Behavior
The accessible div
with role="alert|status"
doesnāt have any content.
Itās is not anywhere that youāre not supposed to pass as children anything that relies on a react context. This makes it impossible to use your awesome accessible alert component with most of css-in-js libraries.
Expected behavior
To render alert without throwing the errors.
Reproducible example
Notice how alert gets fired for the second time with undefined
as a value
CodeSandbox example
Suggested solution(s)
To either specify that you canāt use context consumers as children of @reach/alert
component or to somehow prevent cloning passed children.
Additional context
The error occurs because of this render
call
https://github.com/reach/reach-ui/blob/a376daec462ccb53d33f4471306dff35383a03a5/packages/alert/src/index.tsx#L145-L149
Your environment
Software | Name(s) | Version |
---|---|---|
Reach Package | Alert | 0.10.0 |
React | 16.12.0 | |
Browser | Any | |
Assistive tech | none | |
Node | any | |
npm/yarn | any | |
Operating System | any |
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Not able to access react state using Context API - Stack Overflow
Try it <AlertContext.Provider value={{setMsg,alerts}}> {props.children} </AlertContext.Provider>.
Read more >Context - React
Context is primarily used when some data needs to be accessible by many components at different nesting levels. Apply it sparingly because it...
Read more >Pitfalls of overusing React Context - LogRocket Blog
In this tutorial, we'll review the potential consequences of overusing React Context and discuss how to use it effectively in your next React...
Read more >Alert - Reach UI
Accessible component to create alert messages for React. ... command line in your project directory, run npm install @reach/alert or yarn add @reach/alert...
Read more >Why I never use React.useContext - JulianāGaramendyā.dev
This function returns a tuple with a provider and a custom hook. It's impossible to leak the Context, and therefore impossible to consume...
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 FreeTop 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
Top GitHub Comments
Then could you please tell if there were any limitations that did not allow us to use portals in the first place? In case somebody (maybe even myself) will stumble upon this issue and would like to open an MR with the fix so they have some context.