feedback
This commit is contained in:
@@ -82,6 +82,12 @@ const CounterContext = createContext(10, counter => ({
|
||||
|
||||
// Example 2. Return a computed value
|
||||
const DoubleContext = createContext(10, num => computed(() => num.value * 2))
|
||||
|
||||
// Example 3. Use a previous value
|
||||
const ColorContext = createContext('info' as Color, (color, previousColor) => ({
|
||||
name: color,
|
||||
colorContextClass: computed(() => (previousColor.value === color.value ? undefined : `color-context-${color.value}`)),
|
||||
}))
|
||||
```
|
||||
|
||||
### 2. Use the context
|
||||
|
||||
@@ -69,7 +69,7 @@ Color contexts rely on the type `Color` defined in `/lib/types/color.type.ts`:
|
||||
|
||||
## Usage
|
||||
|
||||
To get and set the color context in a component, you can use the `useContext` composable, which takes a `ColorContext` (defined in `context.ts`) as first parameter and returns the `colorContextClass`:
|
||||
To get and set the color context in a component, you can pass the `ColorContext` to `useContext` and apply the `colorContextClass` to the root component:
|
||||
|
||||
```ts
|
||||
// ParentComponent.vue
|
||||
|
||||
Reference in New Issue
Block a user