[feature request] useTheme hook
See original GitHub issueIssue type
I’m submitting a …
- bug report
- feature request
Issue description
Current behavior: Not implemented yet.
Expected behavior:
Exposing a custom hook useTheme
to access to theme context value.
Using this hook we can be able to access the current value theme in this manner:
e.x:
import React from 'react';
import { View } from 'react-native';
import { useTheme } from 'themes';
function MyComponent() {
const themeValue = useTheme();
const backgroundColor = React.useMemo(
() =>
themeValue === 'light'
? { backgroundColor: 'blue' }
: { backgroundColor: 'darkblue' },
[themeValue]
);
return <View style={[backgroundColor]}></View>;
}
Related code:
Adding a useContext consuming ThemeContext.
export function useTheme(): ThemeType {
const themeContext = useContext(ThemeContext);
if (isEmpty(themeContext)) {
throw new Error('useTheme must be used within a ThemeProvider');
}
return themeContext;
}
Other information:
I have a fork with useTheme
implemented with tests, but im not able to start expo app -.-
It’s not finished yet but if maintainers are agree and see useful this feature im glad to keep working on this pr. link to repo with useTheme: https://github.com/x0s3/react-native-ui-kitten
Im open to talk else feel free to close this feature request 😃
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:11
Top Results From Across the Web
useTheme - React Navigation
The useTheme hook lets us access the currently active theme. You can use it in your own components to have them respond to...
Read more >useTheme React Hook - useHooks
Hooks are a feature in React that allow you use state and other React features without writing classes. This website provides easy to ......
Read more >Mocking React hooks when unit testing using Jest
Below I mock the base-fetch module which is responsible for making requests to the SWAPI endpoints and returning a JSON object. Instead of ......
Read more >Forget Everything you Learned about React - Hooks Rock!
MaterialUI has provided a custom hook called useTheme to get access to the theme within the component. Next, we call useState to set...
Read more >Using the useResource Hook - Learn React Hooks [Book]
A more powerful way of dealing with requests, is using the axios and react-request-hook libraries. Using these libraries, we have access to features...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@henoktsegaye when using
withStyles
in component you can do@Veikedo We also have already some scripts to generate typescript interfaces for theme, component parameters and other Eva-based things, so it can make work autocomplete in your IDE, but it is also a beta feature
I also want to answer one question that you probably might have: We use dash-case for naming variables because we also have a web framework that is also based on Eva Design System 😃