#Alert component

1 messages · Page 1 of 1 (latest)

quartz pivot
#

What would be the best way to have a component accessible from all the others in the application? What I'm trying to achieve is to have a component that show an Alert message, but all component can trigger it without passing props to all components in the application. Is it possible?

rancid orbit
# quartz pivot What would be the best way to have a component accessible from all the others in...

best way is to have root component wrap all content in a HOC https://yew.rs/docs/advanced-topics/struct-components/hoc

you would have a callback that opens alert, and stuff it into the context (you can make a custom struct to contain it)

your hoc would have a contextprovider<the struct i mentioned> that gives everyone that callback, take in children as prop, and just put those children inside contextprovider

There are several cases where Struct components do not directly support a feature (ex. Suspense) or require a lot of boilerplate code to use the features (ex. Context).