Skip to content
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

Preview of themed component resulted in exception in useTheme.js #787

Open
Dalamar opened this issue Nov 28, 2024 · 1 comment
Open

Preview of themed component resulted in exception in useTheme.js #787

Dalamar opened this issue Nov 28, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Dalamar
Copy link

Dalamar commented Nov 28, 2024

Description
I stumbled upon issue with component preview in the app utilising ThemeProvider.
If I call preview(<MyThemedComponent />) I get Exception within useTheme.js caused by absence of context from ThemeContext

Environment
Development

  • Version of currently used Radon IDE
    • 0.0.24
  • Version of React Native/Expo used in the project.
    • React Native: 0.76.2.
    • Expo 52.0.11
Screenshot 2024-11-28 at 16 29 01
@Dalamar Dalamar added the bug Something isn't working label Nov 28, 2024
@kmagiera
Copy link
Member

kmagiera commented Nov 28, 2024

Thanks @Dalamar for reporting. As discussed on discord, this apparently is expected behavior. For now, preview renders as a standalone application root, so if your components require to have a context provider installed, it need to be rendered along with the preview component.

As pointed out, it would make sense to perhaps cover some common scenarios like for example the one you posted where React Navigation context provider is used. This is something we should definitely consider.

What we'd recommend for the time being would be to create a "shell" component that'd render all context providers that are necessary to test individual components. Then in the preview call you could do:

preview(<Shell><YourComponent/></Shell>)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants