Thanks! Up to now i'd been using writable store values and props to achieve these kind of results, it's interesting to see that Svelte provides a sort of 'pointer'-like behaviour using context.
2:49 correction: It not accessible to any component but only "child" components. In this case, since App is root component (parent of all), then it's available to all.
@@SvelteMastery Thank you for replying. I did some research and this is what Richard Harris said in his online Svelte course: "you can either create handler and parent component passes it down to child component or you can create event and listen to it. one advantage of event system is that it doesn't actually matter if the handler exists or not. so if you are creating a component that is designed to be consumed in a place where you don't know what props gonna get passed into it than that's a nice way to make it decouple from its environment. "
Hi, is there any valid reason why getContext could be undefined in a specific child component, while in other child components it work as intended? I use it in Sapper and in my case setContext is defined in Layout component. It has a callback which I call in children components, which are pages. It works on every page but on index, where it stays undefined.
@@SvelteMastery yeah, I ended up with a mix of context and store to enable reactivity. My initial problem was my bad - somehow I copied layout to the nested route and ended up with two but edited just one of them.
Thanks! Up to now i'd been using writable store values and props to achieve these kind of results, it's interesting to see that Svelte provides a sort of 'pointer'-like behaviour using context.
I was surprised that you could set a function as an accessible context, much like dereferencing a function by its pointer.
love your videos, short and to the point
Thanks, I appreciate that 😊
I love his videos too!
2:49 correction: It not accessible to any component but only "child" components. In this case, since App is root component (parent of all), then it's available to all.
I don't need to involve the application with this Context like in React?
Great tip, Thanks
Svelte looks promising! Thanks!
So simple, amazing!
shouldn't we dispatch custom event from child component to parent component ???
yeah that might be better in this situation.
Nice, and simple to use.
Thanks for this video!
what is the difference in using createeventdispatcher and passing function reference to child components?
i'm not exactly sure but i've had a bug where passing function reference was not working and i fixed it by using dispatch instead
@@SvelteMastery Thank you for replying. I did some research and this is what Richard Harris said in his online Svelte course: "you can either create handler and parent component passes it down to child component or you can create event and listen to it.
one advantage of event system is that it doesn't actually matter if the handler exists or not.
so if you are creating a component that is designed to be consumed in a place
where you don't know what props gonna get passed into it than that's a nice way
to make it decouple from its environment.
"
Hi, is there any valid reason why getContext could be undefined in a specific child component, while in other child components it work as intended?
I use it in Sapper and in my case setContext is defined in Layout component. It has a callback which I call in children components, which are pages. It works on every page but on index, where it stays undefined.
hmm sorry i'm not sure. you have a link to the repo? but tbh, I rarely find a good use of setContext so maybe you can use a store ..?
@@SvelteMastery yeah, I ended up with a mix of context and store to enable reactivity. My initial problem was my bad - somehow I copied layout to the nested route and ended up with two but edited just one of them.
puts a 'thank you' the office meme.
Wow this is easy af, why does React have to make things so complicated?
Thanks