0

Sorry for a newbie question. I tried to search, but it was hard to come up with the right keywords to search for my question. I'm trying to understand the following syntax for Native React.

render() {
    ...
}

Is it calling a function, or defining a function? Also it kind of looks like arrow function from ES6: "() => {...}". However it has a name "render" front of () and there's no "=>" sign. Also there's no keyword "function". Very confused...

Where does this syntax come from, and how does it work? Is it a condensed version of a longer syntax? How would I write in ES5?

Thanks!

jl303
  • 1,461
  • 15
  • 27
  • 3
    [It's just how classes are written in JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) – Ingo Bürk May 16 '18 at 19:48
  • One advice I would give you if you play with react is to install nodejs and use [create-react-app](https://github.com/facebook/create-react-app). You can learn ES6 [here](https://github.com/getify/You-Dont-Know-JS#titles) – HMR May 16 '18 at 19:57

1 Answers1

-3

I don't really write React Native but I do write a lot of ReactJs and I believe it has a lot in common. Render() is one of the lifecycle methods of react. The render function get's called every time that the state or the props of a component get called. In the render you should always have a return statement which return JSX. JSX in a language which looks a lot like HTML but does some fancy stuff for you under the hood. If you would like to learn some more about the lifecycles of React you should have a read in their docs: https://reactjs.org/docs/react-component.html

Bob van 't Padje
  • 685
  • 1
  • 6
  • 17