Skip to content

[Question] How do I create new panel after onReady? #310

Closed Answered by techbech
antoKeinanen asked this question in Q&A
Discussion options

You must be logged in to vote

I do something like the following

const components: PanelCollection<IDockviewPanelProps> = {
	default: (props: IDockviewPanelProps) => {
		return <div>{"Hello world"}</div>;
	},
};

function useDockviewApiRef() {
	const dockviewApi = useRef<DockviewApi | null>(null);
	return {
		onReady: (event: DockviewReadyEvent) => {
			dockviewApi.current = event.api;
		},
		get: () => {
			if (dockviewApi.current == null) {
				throw new Error("Dockview api is not ready");
			}
			return dockviewApi.current;
		},
	};
}

export function Layout() {
	const api = useDockviewApiRef();
	return (
		<>
			<button
				onClick={() => {
					api.get().addPanel({
						id: "my-window",
						title: "my-window",

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@antoKeinanen
Comment options

Answer selected by antoKeinanen
Comment options

You must be logged in to vote
1 reply
@techbech
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants