Open antunespedro80 opened 2 years ago
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>
Hello ! Is it possible to pass width/height as string to make div fix to parent and not with a static width/height ?