question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to set a Global variable (`globalTypes`) from within a Story?

See original GitHub issue

I managed to add a toolbar icon that sets my locale for my Storybook app, thanks to https://storybook.js.org/docs/react/essentials/toolbars-and-globals#gatsby-focus-wrapper documentation 🎉

But, when I manipulate my “change language button” nothing happens (unsurprisingly), because it cannot change the Storybook global variable state. Is there a way to set my locale variable? Through hooks maybe? I couldn’t find any documentation about this.

Video showcasing the behavior difference: https://youtu.be/nbvkXpRWz24

It’s not highly critical, but if there is a way for me to make the story preview behave as in the main app, that’d be great!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
shilmancommented, Feb 25, 2021

There is a useGlobals hook but I haven’t tried it in a story:

https://github.com/storybookjs/storybook/blob/next/lib/api/src/index.tsx#L448-L455

1reaction
Vadorequestcommented, Feb 25, 2021

I’ll give it a try when I find some time and keep you updated. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create a global variable in TypeScript - Stack Overflow
I want to be able to call log.Debug from any file without having to import and create objects.) typescript.
Read more >
Theme switching with globals and parameters in decorators
In the previous lesson, we created a decorator to add theme support to Storybook. Although it's working well, in order to switch the...
Read more >
Generate Code for Global Data - MATLAB & Simulink
Declare Global Variables. When using global data, you must first declare the global variables in your MATLAB code. Consider the use_globals function that...
Read more >
Can you change a global variable's value from within a function?
This is a conceptual question rather than one specifically about the lesson. I understand the idea that a local variable is independent of...
Read more >
How to Avoid Using Global Cypress Variables - Gleb Bahmutov
Avoid clashing global types between Cypress and Jest by using local-cypress library. Global variables are the worst thing in programming, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found