Skip to content
Advertisement

I don’t know why I get this, if it is according to the React manual

I tell him I am transferring an event from the component child ( ItemCount) to the parent component parent ItemDetail the onADD event that only acts if an item is passed to it and when it does, the state becomes true.

The child has an event called add to cart which triggers the event and passes a product counter.

It runs perfectly but it throws me a warning that is the following.

react-dom.development.js:86 Warning: Functions are not valid as a React child. This may happen if you return a Component instead of from render. Or maybe you meant to call this function rather than return it.

Can you tell me the mistake and what I did wrong? from now very grateful

I share the codes Thanks

ItemCount (component child)

JavaScript

ItemDetail (component father)

JavaScript

Advertisement

Answer

JavaScript

Here, you are trying to render a component, but actually avisarStock is a function which sets state and opens an alert. It makes no sense to try to render this function.

It would appear you meant to render stock not avisarStock. This would show your stock state in the <h2>:

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