Skip to content
Advertisement

How to pass a function to a component using arrow function?

FYI: I am using ES6 on ReactJS

I have a switcher. I need it to switch to the other side when clicked. If click on the side that is currently active does nothing.

Here is my sample code

JavaScript

Here is the code inside the CustomSwitcher

JavaScript

However I got this error

JavaScript

As I understand, when passing a function down to a component. The function is no longer a function.

And I don’t think my code is good. If you can think of a better way to do so. Please contribute.

Advertisement

Answer

You are not using the correct way to access the props.

Try to replace

JavaScript

with

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement