- What is the difference between state and props?
My answer: The difference between state and props is both __state and props hold infomation that would be displayed to your, state is managed within the component whereas props gets passed to the component. props are immutable and state start with a default value but often gets mutated.
Class answer:Props are immutable properties that pass data to a component when the component is rendered.
State is created within the component. State is mutable. We can initialize state with an initial value. State is persistent with each rerender. Update state triggers a rerender.
- What is the
useState
hook? What doesuseState
return?
My answer: The useState
hook is a Hook that lets you add React state to function components. The useState
returns an array with a stateful value, and a function to update it.
Class answer: useState
is a hook that allows you to add state to your function components. useState
returns an array with two elements. The first element is a pointer to initial state. The second is a function that allows us to reassign that value.
You will make a MultiLingualGreeting
component:
- It should render as a greeting (perhaps, "Good Morning") in English.
- Beneath this greeting, there should be a series of buttons.
- Each button should correspond to a different language (perhaps, "Spanish", "Haitian Creole", and "Portuguese").
- When a button is clicked, the greeting above should be translated to the appropriate language.
greetings ={
"Espanol":"Buen Dias",
"Kreyole": "Bonjou",
"Portugues": "Bom Dia",
"Hindi":"Shubh Prabat"
};