Skip to content

Commit 4919569

Browse files
committed
update docs and examples for the exchange of in useTargetFromContext favor of targetRef="from-context"
1 parent a112c2f commit 4919569

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

docs/handles/handle-component.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ Normally, an interaction is canceled when the user releases the button that star
4141
**handleRef**
4242
Allows overriding to pass a custom handle object.
4343

44-
**useTargetFromContext**
45-
Required to use the target provided by a surrounding `HandleTarget` component.
44+
**targetRef**
45+
Allows to pass in a ref to an object that should be the target of the handle. Alternatively `targetRef` can be set to `"from-context"` use the target provided by a surrounding `HandleTarget` component.
4646

4747
**getHandleOptions**
4848
Allows passing a function that dynamically generates options to override the current handle options.
@@ -76,15 +76,15 @@ Allows retrieval of a reference to the internal handle store (`<Handle ref={hand
7676

7777
## Handle Target Component
7878

79-
The `HandleTarget` component allows declaratively specifying a handle target that is hierarchically above the `Handle` component. To prevent accidentally providing a different target to a handle, using the target from the context requires setting the `useTargetFromContext` on the `Handle` component.
79+
The `HandleTarget` component allows declaratively specifying a handle target that is hierarchically above the `Handle` component. To prevent accidentally providing a different target to a handle, using the target from the context requires setting `targetRef="from-context"` on the `Handle` component.
8080

8181
**Example**
8282
```tsx
8383
<HandleTarget>
8484
<group>
8585
<mesh>
8686
<boxGeometry />
87-
<Handle useTargetFromContext>
87+
<Handle targetRef="from-context">
8888
<mesh position-x={2}>
8989
<boxGeometry />
9090
</mesh>

docs/handles/introduction.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function Door() {
2727
<mesh geometry={nodes.Plane001_Glossy_0.geometry} material={materials.Glossy} />
2828
<mesh geometry={nodes.Plane001_Door_0.geometry} material={materials.Door} />
2929
<mesh geometry={nodes.Plane003_Door_0.geometry} material={materials.Door} position={[0.852, 0.017, 0.782]} />
30-
<Handle useTargetFromContext translate="as-rotate" rotate={{ x: false, y: false, z: [-Math.PI, 0] }}>
30+
<Handle targetRef="from-context" translate="as-rotate" rotate={{ x: false, y: false, z: [-Math.PI, 0] }}>
3131
<group position={[0.81, 0.043, 0.803]}>
3232
<mesh geometry={nodes.Circle002_Glossy_0.geometry} material={materials.Glossy} />
3333
</group>
@@ -41,7 +41,7 @@ export function Door() {
4141
}
4242
```
4343

44-
Next, we need to configure the handle to rotate the door when grabbed. We instruct it to use the target from the context using `useTargetFromContext`, making sure the transformations are applied to the door body. Additionally, we ensure that moving the handle is translated into a rotation using the `translate="as-rotate"` property. Lastly, we disable rotations on all axes except for the `z` axis and limit the rotation between -180° and 0°.
44+
Next, we need to configure the handle to rotate the door when grabbed. We instruct it to use the target from the context using `targetRef="from-context"`, making sure the transformations are applied to the door body. Additionally, we ensure that moving the handle is translated into a rotation using the `translate="as-rotate"` property. Lastly, we disable rotations on all axes except for the `z` axis and limit the rotation between -180° and 0°.
4545

4646
*Learn more about all the available properties for the handle component [here](./handle-component.md).*
4747

examples/editor/app.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export function App() {
143143
<HandleTarget>
144144
<Scene isNotInRT />
145145

146-
<HandleWithAudio useTargetFromContext scale={false} multitouch={false} rotate={false}>
146+
<HandleWithAudio targetRef="from-context" scale={false} multitouch={false} rotate={false}>
147147
<Hover>
148148
{(hovered) => (
149149
<RoundedBox position-x={0.35} position-y={-0.05} args={[0.2, 0.2, 2]} scale={hovered ? 0.125 : 0.1}>
@@ -159,7 +159,7 @@ export function App() {
159159
</HandleWithAudio>
160160

161161
<HandleWithAudio
162-
useTargetFromContext
162+
targetRef="from-context"
163163
scale={{ uniform: true }}
164164
multitouch={false}
165165
translate="as-rotate-and-scale"
@@ -315,7 +315,7 @@ function Screen() {
315315
</NotInXR>
316316
</XRLayer>
317317
<HandleWithAudio
318-
useTargetFromContext
318+
targetRef="from-context"
319319
translate="as-scale"
320320
apply={(state, target) => {
321321
defaultApply(state, target)
@@ -345,7 +345,7 @@ function Screen() {
345345
</HandleWithAudio>
346346
</HandleTarget>
347347
</group>
348-
<HandleWithAudio useTargetFromContext ref={storeRef} scale={false} multitouch={false} rotate={false}>
348+
<HandleWithAudio targetRef="from-context" ref={storeRef} scale={false} multitouch={false} rotate={false}>
349349
<Hover>
350350
{(hovered) => (
351351
<RoundedBox scale={hovered ? 0.125 : 0.1} args={[2, 0.2, 0.2]}>
@@ -385,7 +385,7 @@ function CameraHelper() {
385385
{(hovered) => (
386386
<>
387387
<HandleWithAudio
388-
useTargetFromContext
388+
targetRef="from-context"
389389
apply={(state) => cameraStore.getState().setCameraPosition(...state.current.position.toArray())}
390390
scale={false}
391391
multitouch={false}
@@ -471,7 +471,7 @@ function Scene({ isNotInRT = false }: { isNotInRT?: boolean }) {
471471
{isNotInRT && (
472472
<>
473473
<HandleWithAudio
474-
useTargetFromContext
474+
targetRef="from-context"
475475
apply={(state) => useSceneStore.setState({ lightPosition: state.current.position.toArray() })}
476476
scale={false}
477477
multitouch={false}
@@ -595,7 +595,7 @@ function CustomTransformHandles({
595595
if (isInXR) {
596596
return (
597597
<HandleTarget ref={targetRef}>
598-
<HandleWithAudio useTargetFromContext apply={apply}>
598+
<HandleWithAudio targetRef="from-context" apply={apply}>
599599
{children}
600600
</HandleWithAudio>
601601
</HandleTarget>

examples/handle/door.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function Door(props: JSX.IntrinsicElements['group']) {
4141
material={materials.Door}
4242
position={[0.852, 0.017, 0.782]}
4343
/>
44-
<Handle useTargetFromContext translate="as-rotate" rotate={{ x: false, y: false, z: [-Math.PI, 0] }}>
44+
<Handle targetRef="from-context" translate="as-rotate" rotate={{ x: false, y: false, z: [-Math.PI, 0] }}>
4545
<group position={[0.81, 0.043, 0.803]}>
4646
<Handle
4747
stopPropagation={false}

packages/react/handle/src/component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const Handle = forwardRef<
4141
if (targetRef === 'from-context') {
4242
if (contextHandleTargetRef == null) {
4343
throw new Error(
44-
`no HandleTarget found in the context of this handle while 'useTargetFromContext' is set. Either wrap the Handle in a <HandleTarget> or remove the 'useTargetFromContext' flag.`,
44+
`no HandleTarget found in the context of this handle while 'targetRef="from-context"' is set. Either wrap the Handle in a <HandleTarget> or remove the 'targetRef="from-context"' property or set it to an ref.`,
4545
)
4646
}
4747
targetRef = contextHandleTargetRef

0 commit comments

Comments
 (0)