Skip to content
Advertisement

ReactJS: How do i give action to a button and store that?

I just want to give an action to a TR button but also it will run when i press after Search button. Here is my code:

JavaScript

I created function changeLang() above but it changes immediately. And here is my code inside return()

JavaScript

So, i want to change language of Humidity,Visibility and Wind Speed when i press TR button then pressing Search button.Think that TR and EN buttons are toggle button.

WEBSITE

Advertisement

Answer

You could create a state with a boolean and check whether turkish is set to either true or false. This you could toggle with a button. Once you have that state you can write a simple line in your JSX code to change the content of it, something similar to this:

JavaScript

Then within you JSX code you could use

JavaScript

Or you could even declare these strings earlier by storing them in a variable and then using the variable in the jsx code.

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