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

152
Views
document.getElementById in react using fabric js

How I can change the JavaScript code into React?

document.getElementById('text-color').onchange = function() {
  canvas.getActiveObject().setFill(this.value);
  canvas.renderAll();
};

Note that I am using Fabric.js library. Here is my code:

export default function App() {

  const { editor, onReady } = useFabricJSEditor();

  onAddCircle = () => {
    editor.addCircle();
  };

  const onAddRectangle = () => {
    editor.addRectangle();
  };


  function insertText() {
    editor.canvas.add(new fabric.IText('Tap and Type', {
      left: 40,
      top:   100,
      fontFamily: 'comic sans ms',
      fill: 'red',
      fontSize: 28,

    }));
  }


  //just added this in
  return (
    <div className="App">
      <Navbar />

      <div className="bg-light border-top p-4 mb-3">
        <h1 className="display-5">Customize Your Shirt</h1>
      </div>
    </div>

source: https://codepen.io/psbolden/pen/NbLJbV

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

0

In Reactjs you can attach the whole function to the onChange event

Something like this:

<input
  onChange={function () {
    canvas.getActiveObject().setFill(this.value);
    canvas.renderAll();
  }}
  type="color"
  value=""
  id="text-color"
  size="10"
/>;
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!