You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it works pretty well, if you prefer that sort of thing to the standard context API, but it might be nice if App.svelte looked like this instead:
<script>
import ChildComponent from './ChildComponent.svelte';
- import { Provider } from './ThemeContext.js';+ import ThemeContext from './ThemeContext.js';
let theme = 'light';
</script>
<select bind:value={theme}>
<option>light</option>
<option>dark</option>
</select>
<ThemeContext.Provider value={theme}>
<ChildComponent />
</ThemeContext.Provider>
I can see this being useful in other scenarios as well, e.g. if a package exported multiple components that were designed to be used together:
Was just playing around with an interpretation of React's
createContext
/useContext
API:https://svelte.dev/repl?version=3.0.0&gist=2a110c18df550964f9b31aa2425eaaf1
I think it works pretty well, if you prefer that sort of thing to the standard context API, but it might be nice if
App.svelte
looked like this instead:I can see this being useful in other scenarios as well, e.g. if a package exported multiple components that were designed to be used together:
The text was updated successfully, but these errors were encountered: