-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
addon-docs MDX: State management #9602
Comments
You can use hooks in MDX stories: |
@shilman Ah, thank you very much - super useful! Have a great day! |
@shilman I noticed a few funny things when attempting to get this to work, and wasn't sure if it may merit another issue being opened for each. Spacing between code lines isn't allowed:
Notice the blank lines after the state declaration and in the
When I remove those blank-lines, all is well. Emotion
|
Somehow I come across a problem in this way, the {() => {
const [count, setCount] = useState("1");
const Wrap = styled.div`
height: 200px;
width: 100%;
background-color: #eee;
padding: 15px;
box-sizing: border-box;
`;
return (
<Wrap>
<MyTabs defaultActiveKey={count} onChange={setCount} />
</Wrap>
);
}} when I trigger when I try to implement it on codesandbox , Eslint yields "React Hook "useState" cannot be called inside a callback. React Hooks must be called in a React function component or a custom React Hook function. (react-hooks/rules-of-hooks)eslint" In other words: seems |
Does using a function as a child only work directly under a |
@sami616 yeah i think there's some special magic for that in the |
Thanks for the reply, worth adding a feature request? i cant imagine i'm the only person that would benefit from this. |
For anyone who comes across this, you can write a little utility component which handles this: type FunctionProps = {
children: () => React.ReactNode
}
export const Function = ({ children }: FunctionProps) => children() |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook! |
this worked nicely! one thing I'm running into when trying to follow this example is the formatting (see screenshot) im on v6.5.9 of storybook, and have the following in
from issue #8078 (comment) any idea on how to fix this formatting when using the example you provided? (e.g. the indentation) |
I may have overlooked this since the docs are still being worked on for MDX, but what's the way to manage state in my stories using MDX? Right, now, I'm importing a component that handles the state management in a normal
.js
file, but then the code examples are a bit lackluster in the<Preview />
window:The text was updated successfully, but these errors were encountered: