• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How do I handle onChange events within an internal Component

Resolved: How do I handle onChange events within an internal Component

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have a simple slider that is not working when it is placed inside a Component. It works fine when it is outside the component.
In the following code I have a simple block of JSX. When I render the block as JSX it works perfectly. When I render the same block from inside a functional Component, the slider moves once, registers the proper state change, and then stops after the first onChange event.
I have a good bit of code written as plain functions. I am trying to use useSwipeable (for touch support), which is a hook and must be called from within a Component (according to the error message I get).
Could anyone help me understand why the Componentized block doesn’t work?
Code is also available at CodeSandbox
Thanks, Bill

Answer:

Your implementation is not correct. You are creating a component inside a component which is okay but in the same time you are trying to update state of main component with <TestComponent/>. Correct implementation is the second way that you do as {testFunction()}. If you want to keep your component like this, you should create a state inside TestComponent but best practice would be creating another file for TestComponent and putting state inside of it. I updated your code to make it work, here is the working sample https://codesandbox.io/embed/component-function-events-forked-m5wj4b?fontsize=14&hidenavigation=1&theme=dark

If you have better answer, please add a comment about this, thank you!

reactjs
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to compare two text files and and change the sign of the data in powershell?

27/03/2023

Resolved: Java Virtual Machines deleted

27/03/2023

Resolved: PyCharm cannot see my newly compiled .pyc see on import

27/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.