new attrs as a function doesn't pass theme to the function provided
See original GitHub issueEnvironment
- React-native IOS
System:
- OS: macOS High Sierra 10.13.6
- CPU: x64 Intel® Core™ i5-5350U CPU @ 1.80GHz
- Memory: 43.83 MB / 8.00 GB
- Shell: 5.6.2 - /usr/local/bin/zsh
Binaries:
- Node: 11.0.0 - /usr/local/bin/node
- Yarn: 1.12.1 - /usr/local/bin/yarn
- npm: 6.4.1 - /usr/local/bin/npm
- Watchman: 4.9.0 - /usr/local/bin/watchman
npmPackages:
- styled-components: ^4.1.1 => 4.1.1
Reproduction
- create a global theme and provide it using <ThemeProvider>.
- create a styled component with attrs, where the function expects a theme to be in the props. (eg, `styled.div.attrs(props => ({ backgroundColor: props.theme.bgcolor}))```)
Expected Behavior
theme is provided to the props of the attrs function
Actual Behavior
theme is not provided and the app crashes with “cannot read property ‘bgcolor’ of undefined”.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Passing props to MUI styles - reactjs - Stack Overflow
Solution for how to use both props and theme in material ui : ... function SimpleCard(props) { // in demo.js const { classes,...
Read more >API Reference - styled-components
A function that receives the props that are passed into the component and computes a value, that is then going to be merged...
Read more >attr() - CSS: Cascading Style Sheets - MDN Web Docs
The attr() CSS function is used to retrieve the value of an attribute of the selected element and use it in the stylesheet....
Read more >Introducing script attributes related functions in WordPress 5.7
WordPress 5.7 adds a handful of new functions that enables passing attributes, such as async or nonce , to both regular and inline...
Read more >API Reference - attrs 22.2.0 documentation
This works similarly to attr.evolve but that function does not work with ... It is given the passed-in value, and the returned value...
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 FreeTop 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
Top GitHub Comments
Hi guys, I solved it in the following way:
export const TextInput = styled.TextInput.attrs(({theme}) => ({ placeholderTextColor: theme.colors.primary, }))
font-family: ${({ theme }) => theme.fonts.interBold}; font-size: 18px; color: ${({ theme }) => theme.colors.primary};;
@NProtagoras looking into this now, thanks!