refactor(useSetNodeData): put function in useReactFlow/useSvelteFlow
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { memo, ChangeEventHandler } from 'react';
|
||||
import { Position, NodeProps, useSetNodeData, Handle } from '@xyflow/react';
|
||||
import { Position, NodeProps, Handle, useReactFlow } from '@xyflow/react';
|
||||
|
||||
function TextNode({ id, data }: NodeProps) {
|
||||
const setNodeData = useSetNodeData();
|
||||
const { updateNodeData } = useReactFlow();
|
||||
|
||||
const onChange: ChangeEventHandler<HTMLInputElement> = (evt) => setNodeData(id, { text: evt.target.value });
|
||||
const onChange: ChangeEventHandler<HTMLInputElement> = (evt) => updateNodeData(id, { text: evt.target.value });
|
||||
|
||||
return (
|
||||
<div style={{ background: '#eee', color: '#222', padding: 10, fontSize: 12, borderRadius: 10 }}>
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { memo, useEffect } from 'react';
|
||||
import { Position, NodeProps, useSetNodeData, Handle, useHandleConnections, useNodesData } from '@xyflow/react';
|
||||
import { Position, NodeProps, useReactFlow, Handle, useHandleConnections, useNodesData } from '@xyflow/react';
|
||||
|
||||
function UppercaseNode({ id }: NodeProps) {
|
||||
const { updateNodeData } = useReactFlow();
|
||||
const connections = useHandleConnections({
|
||||
type: 'target',
|
||||
});
|
||||
const nodeData = useNodesData(connections[0]?.source);
|
||||
const setNodeData = useSetNodeData();
|
||||
|
||||
useEffect(() => {
|
||||
setNodeData(id, { text: nodeData?.text.toUpperCase() });
|
||||
updateNodeData(id, { text: nodeData?.text.toUpperCase() });
|
||||
}, [nodeData]);
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user