Issue
hi everyone i am new to react native. Reading the documentation and seeing various examples, I didn't quite understand a few things:
- code:
const Hello = () => {
return (
<div>hello</div>
)
}
and code:
Hello() {
return (
<div>Hello</div>
)
}
are the same, i.e. do they have the same meaning?and how can I recall them for example when the application starts?
2)and what is the meaning of: const [A, B] = useState ()? what do A and B mean?
Solution
Ahh , see for first its mostly a Javascript thing. in RN we return JSX
const Hello = () => {
return (
<div>hello</div>
)
}
stands for const fun = () => {}
And this
Hello() {
return (
<div>Hello</div>
)
}
stands for function fun() {}
Thats it.
For point 2 :
const [name, setName] = useState ("johndoe") // 0 is default value
useState is a hook , which is a react feature, here for suppose you want a variable called name and you want to display it in your app.
IF you just do let name = "johndoe" in react and render it, it will display john doe. But if you update its value like name = "messi" , in app screen it will still display john doe rather than messi.
Hence there's useState which rerenders the screen. So for above
you can update name via setName("messi")
and voila you now get messi being displayed in app.
i suggest you to follow this YT article to understand better
Hope it helps. feel free for doubts
Answered By - Gaurav Roy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.