Hook to detect if component is selected in editor

Would it be possible to add a way to detect if a code component is currently selected in the Plasmic editor?

Use case: For components like accordions, tabs, or collapsible sections, it would be really helpful to show their content when selected in the editor - even when they’re closed in their default state. Right now you have to manually open them to edit the content inside.

Proposed API: Something like:

const { isSelected } = usePlasmicCanvasContext();

Or a separate hook:

const isSelected = usePlasmicSelected();

This would make editing complex interactive components much smoother. Thoughts?

Turns out this already exists:

const { isSelected, selectedSlotName } = usePlasmicCanvasComponentInfo(props) ?? {};
2 Likes