innerRef example on documentation with styled()
See original GitHub issueI am trying the following code on the documentation
https://www.styled-components.com/docs/advanced#refs
const Input = styled.input`
padding: 0.5em;
margin: 0.5em;
color: palevioletred;
background: papayawhip;
border: none;
border-radius: 3px;
`;
class Toto extends React.Component {
render() {
return (
<input {...this.props} />
);
}
}
const Input2 = styled(Toto)`
padding: 0.5em;
margin: 0.5em;
color: palevioletred;
background: red;
border: none;
border-radius: 3px;
`;
const Form = () => (
<Input
placeholder="Hover here..."
innerRef={x => this.input = x}
onMouseEnter={() => this.input.focus()}
/>
);
const Form2 = () => {
<Input2 placeholder="Hover here..."
innerRef={x => this.input2 = x}
onMouseEnter={() => this.input2.focus()}
/>
}
render(
<div>
<Form />
<Form2 />
</div>
);
I would like to see a working demo of the innerRef
using my demo. I wasn’t able to produce it due to JS errors :
VM802:29 Uncaught TypeError: Cannot read property 'focus' of null
This seems to happen when I edit too much the javascript in the page.
Could it possible to see both example working ?
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Advanced Usage - styled-components
This example renders our above themed Button and a second one that uses a second ThemeProvider to invert the background and foreground colors....
Read more >reactjs - Styled Components v4 refObject - Stack Overflow
I am following how the docs from styled-components have explained to ... I have even tried to use the forwardRef as various examples...
Read more >masking inputs and more ref fun | /*code-comments*/
From the docs: For example, to use with styled-components, which requires an innerRef: <MaskedInput mask={['(', /[1-9]/, /\d/, /\d/, ...
Read more >Styled Components - Emotion
Styling elements and components. styled is very similar to css except you call it with an html tag or React component and then...
Read more >Advanced Guides - Glamorous
You can accomplish this with the innerRef prop. ... With CSS in JS, the goal is to style components and reuse those components....
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
I am having a similar issue. I have a Button styled component:
<Button innerRef={(elem) => this.btn = elem} />
but I am getting
null
returned when doing this:console.log(this.btn);
If I use ‘ref’ instead of ‘innerRef’, then I get the StyledComponent object back. Are you able to advise?
Gist: https://gist.github.com/joetidee/5316feb0a39b52bf9b48399888258781
@joetidee See https://github.com/jxnblk/styled-system/pull/188