Skip to content

Commit

Permalink
Update shared-state.md
Browse files Browse the repository at this point in the history
fixing the vue tabs
  • Loading branch information
whitespacecode authored Nov 12, 2024
1 parent 64f228c commit 05602e6
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions docs/cookbook/shared-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,6 @@ With the mesh assigned to the reactive state, it's available throughout your pro

::: code-group

```ts [composables/state.ts]
import { reactive, toRefs } from "vue";

const state = reactive({
mesh: null,
//you can add more objects here
})

export function useState() {
return {
...toRefs(state)
}
}
```

```vue [App.vue]
<script setup lang="ts">
import { BoxGeometry, Mesh, MeshNormalMaterial } from 'three';
Expand Down Expand Up @@ -71,6 +56,22 @@ const { mesh } = useState();
</template>
```

```ts [composables/state.ts]
import { reactive, toRefs } from "vue";

const state = reactive({
mesh: null,
//you can add more objects here
})

export function useState() {
return {
...toRefs(state)
}
}
```
:::

## Using TresMesh components

You can also add TresMesh components to the reactive state. Here, we'll use a reference and assign it to the state when mounted.
Expand Down Expand Up @@ -151,4 +152,6 @@ onMounted(() => {
</template>
```

:::

With these steps, you can easily manage and share objects across different components in your Vue 3 project using a reactive composable.

0 comments on commit 05602e6

Please sign in to comment.