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

196
Views
After importing third-party Javascript library, it only reads images from index.html page. Is it because it does not support react?

I am trying to use a third-party javascript library in my react app (https://github.com/giventofly/pixelit). Since there was no npm package I downloaded the js file and imported it. It is supposed to take the image by its id and pixel it with the chosen colour palette. However, it is only able to read images on the index.html page and not that have been rendered in the JSX file. Is it because the library does not support react? or am I doing anything wrong?

Following is the working example provided:

<img src="assets/sky.jpg" id="pixelitimg" alt="" />
<canvas id="pixelitcanvas"></canvas>
<script>
  const mypalette = [
    [26, 28, 44],
    // ...
  ];
  const px = new pixelit({
    from: document.getElementById("pixelitimg"),
    palette: mypalette,
  });
  px.draw().pixelate().convertPalette();
</script>

This is how I use it:

import { pixelit } from "./pixelit";

const renderImage = () => {
  const mypalette = [
    [26, 28, 44],
    // ...
  ];
  const px = new pixelit(document.getElementById("pixelitimg"), mypalette);
  px.draw().pixelate().convertPalette();
};

return (
  <div>
    <img src={twitterLogo} id="pixelitimg" alt="" />
    <canvas id="pixelitcanvas"></canvas>
    {renderimage()}
  </div>
);

The react page doesn't show anything. However,when I add the image element and canva element in the index.html page, it works as intended.

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

0

I'm not sure if this is the cause of the error, but interacting directly with the DOM in React is not very good. You need to create a ref to the image.

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!