React hooks do not overwrite styles [TypeScript]
See original GitHub issueEnvironment
System:
- OS: macOS 10.14.4
- CPU: (4) x64 Intel® Core™ i5-6287U CPU @ 3.10GHz
- Memory: 166.97 MB / 16.00 GB
- Shell: 5.3 - /bin/zsh
Binaries:
- Node: 10.15.2 - /usr/local/bin/node
- Yarn: 1.15.2 - /usr/local/bin/yarn
- npm: 6.9.0 - /usr/local/bin/npm
- Watchman: 4.9.0 - /usr/local/bin/watchman
npmPackages:
- babel-plugin-styled-components: ^1.10.0 => 1.10.0
- styled-components: ^4.1.3 => 4.1.3
Reproduction
I import a file which is a React Hook and want to override the color. But there is no effect on that 😢
// Modules
import React, { Fragment } from "react";
import styled from "styled-components";
// Hook
const MyHookTitle = () => {
const InternalTitle = styled.h1`
color: purple;
`;
return <InternalTitle>MyHookTitle</InternalTitle>;
};
// Styles
const StyledHook = styled(MyHookTitle)`
color: red;
`;
export const App = () => {
return (
<Fragment>
<MyHookTitle />
<StyledHook />
</Fragment>
);
};
Expected Behavior
Color of title is red
.
Actual Behavior
Color is purple
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top Results From Across the Web
TypeScript and React: Hooks - fettblog.eu
A function that is called without any parameters. This is the side-effect you want to call. · An array of values of type...
Read more >Rules of Hooks - React
They let you use state and other React features without writing a class. Hooks are JavaScript functions, but you need to follow two...
Read more >React Hooks cheat sheet: Best practices with examples
React useState and setState don't make changes directly to the state object; they create queues to optimize performance, which is why the ...
Read more >React Hooks - Modified state not reflecting immediately
Much like setState, the state update behaviour using hooks will also require a re-render and update and hence the change will not be ......
Read more >FAQs - styled-components
If you're using React Native, you'll need at least v0.59 (the first version to support hooks.) That's it.. styled-components v5 does not introduce...
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
@nachbarshund
InternalTitle
is still in the render lifecycle. As mentioned in https://github.com/styled-components/styled-components/issues/2477#issuecomment-479510128, we shouldn’t be doing that.InternalTitle
needs to be moved outside ofMyHookTitle
and theclassName
needs to be passed down in order forStyledHook
’s styles to apply.Here’s a codesandbox of the above code https://codesandbox.io/s/9ol8molq4o
@epilande Oh man big thanks. No I’ll get the point here. Thanks for helping 🚀