Issue related to passing a ref prop (property 'slider' does not exist on type 'xyz')
See original GitHub issueSo I’ve been trying to pass refs to the slider component and yet had no luck. I found a similar issue #1261 which lead me to this file and with the code example
This is how my component looks like
<Slider
ref={slider => (this.slider = slider)}
{...carouselSettings}
className={fade ? 'slick-fade' : null}
>
{children}
</Slider>
and here is the issue I’m having
ERROR in [at-loader] ./src/components/molecules/Carousel/index.tsx:53:38
TS2339: Property 'slider' does not exist on type 'Carousel'.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top Results From Across the Web
property '$refs' does not exist on type - You.com
QUESTION ANSWERS. Trying to auto-focus on the next input field after 1 character is typed. Getting error: Property '$refs' does not exist on...
Read more >Property 'ref' does not exist on type 'IntrinsicAttributes'
I don't see any error when replicate your code. But it does have 1 error at runtime: Warning: Function components cannot be given...
Read more >TypeScript Fundamentals - Joy of Code
You can't access any object properties unless you type narrow first and then use type assertion; Type unknown can only be assigned to...
Read more >React: Property 'X' does not exist on type 'Readonly<{}>'
The React.js error "Property does not exist on type 'Readonly<{}>'" occurs when we try to access the props or state of a class...
Read more >Safari Technology Preview Release Notes - Apple Developer
Note: Tab Groups do not sync in this release. Web Inspector. Elements. Added CSS keyword completions for standard logical properties (r280588). Console. Fixed ......
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
This is great! thanks a lot. You can also achieve the same thing with Function Components and Hooks:
Sorted it by
slider: ISlider;
and bindingthis.slider = React.createRef();
in the constructor. Then I just passedref={this.slider}
to the slider component as a prop. To pass the typescript issue, I’ve initially assignedslider: any
, but then replaced it with an empty interface and started digging around the props it takes.