tbolis / react-sketch

Sketch Tool for React-based applications, backed up by FabricJS
http://tbolis.github.io/showcase/react-sketch/
MIT License
678 stars 230 forks source link

Is there any version of this code as a functional component? #177

Open kanishkkp opened 1 year ago

sojinsamuel commented 10 months ago

Will this do:

import { useState } from 'react';
import { SketchField, Tools } from 'react-sketch';

const ReactSketch = () => {
  const [tool, setTool] = useState(Tools.Pencil); 
  const [lineColor, setLineColor] = useState('black'); 

  return (
    <div>
      <SketchField
        width="800px" 
        height="400px"
        tool={tool} 
        lineColor={lineColor}
      />
      <button onClick={() => setTool(Tools.Pencil)}>Pencil</button>
      <button onClick={() => setTool(Tools.Rectangle)}>Rectangle</button>
      {/* Add more buttons for different tools if needed */}
    </div>
  );
};

export default DrawingComponent;