Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
to integrate fabric.js rectangle in react
import { fabric } from 'fabric';
const Canvas = () => {
  const [canvas, setCanvas] = useState('');  
  useEffect(() => {
    setCanvas(initCanvas());
  }, []);  
  
  const initCanvas = () => (
    new fabric.Canvas('canvas', {
      height: 800,
      width: 800,
    })
  ); 
  const addRect = canvi => {
    const rect = new fabric.Rect({
      height: 280,
      width: 200,
      fill: 'yellow'
    });
    canvi.add(rect);
    canvi.renderAll();
  }
  
  return(
    <div>
      <button onClick={() => addRect(canvas)}></button>
     <br/><br/>
     <canvas id="canvas" />
    </div>
  );
}
export default Canvas;

I want to display the rectangle without using the button and also to display its state on the browser the onload event is also not working in the react I also tried to use the other alternative of onload but it's of no help

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I'm also working on this if you want to add rect without button click you can add it into the useEffect.

const fuctionName = ()=>{

useEffect(() => {



  return () => {

 const canvas = new fabric.Canvas('canvas-main');


 const rect = new fabric.Rect({

     height: 280,

      width: 200,

      fill: 'yellow',

    });

 canvas.add(rect);

  }
}, [])

 return (
    <>
      <canvas


        style={{ border: 'solid 1px #555' }}


        id="canvas-main"


        width="600px"


        height="600px"
      />
    </>
  );
};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!