Skip to content
Advertisement

React Functional Component Parent and Child – Unhandled Rejection (TypeError): X is not a function

  • I have a parent app which contains a handler function (handleChallengeSave).
  • The handler function triggers a useState (setSavedChallenge) in the parent.
  • The handler function is passed down as props to the child.

I’m getting an ‘Unhandled Rejection (TypeError): X is not a function’ error. However if I change nothing other than moving the state to the child, it works.

Eg:

This doesn’t work:

Parent (App.js)

JavaScript

The Child (Home.js)

JavaScript

Any help MUCH appreciated!

Advertisement

Answer

Issue

The Route component doesn’t pass additional props on to children.

Solution

Render Home on the render prop to pass in additional props.

JavaScript

Or render Home as a child component.

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