-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Example usage with Next.js #81
Comments
Hi @optimistiks. Thanks for the feedback 🙏. I'll take a look, make sure I understand what's going on, then add this to the documentation. |
To add, the suggested approach using |
The library is now being successfully used in several NextJS projects. I will check what the status is. |
Any updates on this? I'm trying with NextJS 13 but I don't get the blue bars rendered on hover. It looks like its SSRing and showing the smallest possible container size. |
Would you be so kind to link a working example? I am not able to make the Panes work, nor register a ref successfully with Next12 and React 18. the |
Based on the linked code sandbox, I created this hook, it works but has an issue.
If you have a fix for it, please post it (probably import { ComponentType, Ref, useEffect, useRef, useState } from "react";
import { AllotmentHandle, AllotmentProps, PaneProps } from "allotment/dist/types/src/allotment";
function useAllotment() {
const isMountedRef = useRef(false);
const allotmentRef = useRef<AllotmentHandle>({
resize: (sizes = [0, 0]) => {
console.warn("Allotment is not mounted yet", sizes);
},
reset: () => {},
});
const [Allotment, setAllotment] = useState<
ComponentType<AllotmentProps & { ref?: Ref<AllotmentHandle> }> & {
Pane: ComponentType<PaneProps>;
}
>(
() => {
function Allotment({ children }: AllotmentProps) {
return <>{children}</>;
}
Allotment.Pane = function ({ children }: PaneProps) {
return <>{children}</>;
};
return Allotment;
},
);
useEffect(() => {
isMountedRef.current = true;
import("allotment")
.then(mod => {
if (!isMountedRef.current) {
return;
}
setAllotment(mod.Allotment);
})
.catch(err => console.error(err, `could not import allotment ${err.message}`));
return () => {
isMountedRef.current = false;
};
}, []);
return { allotmentRef, Allotment };
}
export default useAllotment; |
I can confirm I got allotment working with my Next.JS v13 app I did need to use the dynamic export Here is what I did...
|
The suggested approach (to use
next/dynamic
) did not work for me. I could not useAllotment.Pane
after dynamically importing withssr:false
, neither fromallotment
directly nor from an intermediate component file.But I got it to work using combination of plain
import
anduseEffect
just fine.https://codesandbox.io/s/nextjs-typescript-allotment-c7yvk?file=/components/Panes.tsx
The text was updated successfully, but these errors were encountered: