-
Notifications
You must be signed in to change notification settings - Fork 12
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
Usage with React #6
Comments
here is example snippet React.useLayoutEffect(() => {
if (!isOpened) {
return
}
const _reference = reference.current
const _popper = popper.current
let nanopop: NanoPop
if (_reference && _popper) {
nanopop = new NanoPop(_reference, _popper, {
margin: 4,
position: 'bottom-end',
})
nanopop.update()
}
// expected behavior
return () => nanopop.destroy()
}, [isOpened]) |
Hi :) NanoPop does not need to be destroyed manually as it does not bind any events to an elemenet. The only reason for re-creating a class is that it's convenient to just call |
Maybe it was a bad design decision to use a class, I'll consider releasing a second version with just a function called |
I would be very grateful to you! |
That lib becomes even better for me lol. Thanks, I think you can close this issue. Cheers |
Can you show me your example of using this plugin? I want to create my own dropdown and use this plugin as a dropdown content positioning tool. |
Version 2 is in progress... I hope this will only take a few days and I'll ping you @7iomka as soon as it's "finish" since there are major API changes :) @mod3x I'll keep this open as long as the second version is in progress, you made me realize that the current API doesn't make that much sense as it's a really low level library to position things. At first I tried to imitate Popper but this is definitely going in a completely separate direction! 😄 |
Okay I've managed to create a minimal demo on codesandbox. Make sure to checkout the latest README :) |
Great work! I'll update to the v2 :) |
Thank you! In prev. version of your lib i write this code ...
const [pop, setPop] = React.useState(null);
const prevTrigger = usePrevious(trigger);
const refUpdate = React.useRef(false);
useEffect(() => {
const isEqKeys = trigger?.key === prevTrigger?.key;
if (!isEqKeys) {
refUpdate.current = true;
}
if (pop && !refUpdate.current) return;
if (!refTrigger?.current || !refContent?.current) return;
if (!isOpen) return;
setPop(
new NanoPop(refTrigger.current, refContent.current, {
forceApplyOnFailure: true,
position: position || 'bottom-middle',
variantFlipOrder: {
start: 'sme',
middle: 'mse',
end: 'ems',
},
positionFlipOrder: {
top: 'tb',
right: 'rltb',
bottom: 'bt',
left: 'lrbt',
},
}),
);
refUpdate.current = false;
}, [pop, isOpen, trigger, prevTrigger, refContent?.current, refTrigger?.current]);
useEffect(() => {
// eslint-disable-next-line no-unused-expressions, @typescript-eslint/no-unused-expressions
showPortal && pop && pop.update();
}, [pop, showPortal, windowWidth, windowHeight]);
... |
My current hack-workaround (with css animation + delay) |
Hey there. Is it safe to use with react lifecycle hooks? As I noticed nanopop has no method to destroy an instance and react will try to create another one every re-render. Thanks
The text was updated successfully, but these errors were encountered: