question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How does `as` props work

See original GitHub issue

Description

I just encountered a problem. When I was using as props to transform ChakraUI’s Box to another 3rd-party functional component, say Form, everyting went well, but Form has its own onSubmit props which collided with that of Box. Here was the problem: the type of onSubmit is still the same as that of Box’s onSubmit props, rather than that of Form’s. If I want to keep the type of Form’s onSubmit after using the as props of Box, what could I do? A sandbox was made for reference. Notice the error reported at Line 41. To try to figure this out, I attempted to find answer by googling or digging into the source code of ChakraUI but in vain. I am very curious about how the as props works? Any response will be highly appreciated. Or if you could point out where is the as related source code? Thanks so much in advance.

Link to Reproduction

https://codesandbox.io/s/epic-christian-3mfvct?file=/src/index.tsx:696-728

Steps to reproduce

  1. Go to ‘…’
  2. Click on ‘…’
  3. Scroll down to ‘…’
  4. See error

Chakra UI Version

2.2.4

Browser

No response

Operating System

  • macOS
  • Windows
  • Linux

Additional Information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
TristanWYLcommented, Jul 24, 2022

Hi @itkrt2y Thanks so much for your exhaustive explanation, and your reply perfectly solves my concerns. I tried so much to dig into ChakraUI’s source code, while ignored that of emotion. Sigh… How stupid I am. Thanks so much!!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Use Props in React - freeCodeCamp
We use props in React to pass data from one component to another (from a parent component to a child component(s)). Props is...
Read more >
What is “Props” and how to use it in React? - ITNEXT
Props stand for properties and is a special keyword in React · Props are being passed to components like function arguments · Props...
Read more >
Components and Props - React
Props are Read-Only ... Such functions are called “pure” because they do not attempt to change their inputs, and always return the same...
Read more >
How passing props to component works in React
In React, states are passed from one component into another component as props. Since prop names and values will just be passed into...
Read more >
Introduction to React Props & How to Use It in Your Code
In React, the term props stands for properties, which refers to the properties of an object. This is because all elements created in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found