rahul2104 / reactjs-pdf-reader

PDF Reader in browser for React js
MIT License
24 stars 11 forks source link

the PDF doesn't rerender when scale change #5

Open hpsaah opened 4 years ago

hpsaah commented 4 years ago

Hi i'am trying to use the component in another react component handling the scale at state but when i change it the pdf doesn't re-render

how can i fix it? i'am doing anything wrong or is a bug in the component?

thanks

shaynethiessen commented 4 years ago

This is a bug. I have the same problem.

FabianoLothor commented 4 years ago

@hpsaah try to add key={scale} in your props.

FabianoLothor commented 4 years ago

Unbeautiful workaround:

...
  const [renderCounter, setRenderCounter] = useState(0);
...
  useEffect(() => {
    setRenderCounter(renderCounter + 1);
  }, [scale]);
...
          <PDFReader
            key={renderCounter}
            scale={scale}
            ...
          />
...
hpsaah commented 4 years ago

Thanks @FabianoLothor, changing the key property of the component you force to rerender

shaynethiessen commented 4 years ago

Thanks for your help!