0

Generating a new component onClick in react

On click i want to generate a new joke which is in another component. Could someone tell me what i am missing. https://codesandbox.io/s/old-cache-gc32p?file=/src/App.js

22nd Feb 2021, 8:05 AM
Dee
5 Answers
+ 4
Dee I used that api to make an example , so you can see if this is something you were looking to do or not, https://code.sololearn.com/WYSh4ohru9VF/?ref=app
22nd Feb 2021, 2:31 PM
Abhay
Abhay - avatar
+ 3
Event trigger function should not be used for create component Joke, use onClick to update state of joke instead. The state then can be passed to component though props. https://code.sololearn.com/W3tRab01frMX/?ref=app
22nd Feb 2021, 3:24 PM
CalviŐ˛
CalviŐ˛ - avatar
+ 1
onClick handler is expecting a function but you are passing an object to it , i.e. the one created using map function . I am not even sure if you have the correct state setup as not every state needs to be mutated. So it will be intersting for me to see what can you change to output what you want or you can just tell what exactly is your program suppose to do so i can try to re arrange it to make it work properly.
22nd Feb 2021, 10:56 AM
Abhay
Abhay - avatar
+ 1
Thank you Abhay and Calvin. This seem to answer my question, let me make them work.
23rd Feb 2021, 4:29 AM
Dee
0
I am using the chuck Norris Api. And i want to have a new joke everytime i click on a particular category based on that particular category. I was trying to simulate that before using the api
22nd Feb 2021, 11:57 AM
Dee