SolidJSS
SolidJSโ€ข3y agoโ€ข
4 replies
anhvu0911

undefined context for dynamically added component

Hi team,

I am coding a toast component. The idea is to expose a success method via context. Users can pass in any components as the first param of the success method to be displayed inside a toast.
Users can use ToastBody as the first param, which will contain a close button. The close button will close the toast via onClose method exposed in the context.

Using React, as demo here https://playcode.io/1290862, the console log context=... prints out correctly the value of the context that the ToastBody is wrapped in.

Using Solid, https://playground.solidjs.com/anonymous/7b30d865-66e4-499e-b346-dbcab04670ba, The console log prints out
undefined


Questions:
- I think this has something to do when the component is created. In Solid case, ToastBody is created much after the ToastContext.Provider is created, so it cannot set the correct owner. What do you think?
- What can I do to get the context in this case?
PLAYCODE.IO
Quickly discover what the solid compiler will generate from your JSX template
Was this page helpful?