Skip to content

Panel Addon Development: How to retrieve user configuration in panel component #27012

Closed Answered by LucaMargadant
LucaMargadant asked this question in Help
Discussion options

You must be logged in to vote

I've figured out a solution that works, so I'll close this discussion.

Users need to add the configuration in their preview.ts or preview.js file. After giving it some thought, this approach makes absolute sense because it allows the parameters to be overridden even at the story level.

const preview: Preview = {
  parameters: {
    someConfigs: {
    },
  },
};

export default preview;

And then we can retrieve it in the tsx Addon Panel like so

import React from 'react';
import { useParameter } from '@storybook/manager-api';

export const AddonPanel = ({ active }) => {
    const someConfigs = useParameter('someConfigs', null);
    console.log(someConfigs);

    return (
        <div styl…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by LucaMargadant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
1 participant