Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static width/height #143

Open
antunespedro80 opened this issue Jan 17, 2022 · 1 comment
Open

Static width/height #143

antunespedro80 opened this issue Jan 17, 2022 · 1 comment

Comments

@antunespedro80
Copy link

Hello !
Is it possible to pass width/height as string to make div fix to parent and not with a static width/height ?

@robsilva
Copy link

robsilva commented Jan 7, 2024

This is how I solved this:

import { useMeasure } from "react-use";
...
  const [ready, setReady]  = useState(false);
   const [ref, { width, height }] = useMeasure();
...
  useEffect(()=>{
    if(width && height) setReady(true);
  },[width, height]);

Then use the ref in the DIV

<div className="parentdiv"  ref={ref}>
   {ready && 
          <WordCloud
            data={keywords}
            width={width}
            height={height}
            font="sans-serif"
            rotate={() => (Math.random() > 0.3 ? 0 : 90)}
            padding={5}
            fill={() => (Math.random() > 0.5 ? "#000" : "#fff")}
            fontWeight="bold"
          />
          }
</div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants