2

Looks like functions which are part of the React framework are referred to as "methods":

"The only method you must define in a React.Component subclass is called render()."

https://reactjs.org/docs/react-component.html

However, this excerpt is from further down in the same webpage:

"The render() function should be pure, meaning that it does not modify component state"

So even in the same webpage on the official React website, render() seems to be referred to as either a function or a method. Do you use any guidelines for using the term "function" vs "method" when discussing these constructs in React? Or in the React world are these two terms completely interchangeable with no real discernment or nuance?

random512
  • 1,017
  • 3
  • 13
  • 19

4 Answers4

1

Do you use any guidelines for using the term "function" vs "method" when discussing these constructs in React?

No guidelines between referring to them either way because both terms are correct. However, I tend to hear render function more instead of render method from my experience.

It's most preferable for using the term "method" when explicitly mentioning/referring to "Class" or "Object" as in the case of the sentence the React docs used:

The only method you must define in a React.Component subclass is called render()

Still, it's up to preference regardless.


For reference on what a method is from MDN:

A method is a function which is a property of an object

https://developer.mozilla.org/en-US/docs/Glossary/Method

kmui2
  • 2,227
  • 18
  • 19
0

Generally the term "method" is used when describing a function that belongs to an object or class.

To use the term function is always correct, the reason react often uses the term "method" is because in react the code is often running inside of a class.

cd3k
  • 719
  • 5
  • 8
0

See What's the difference between a method and a function?.

In React, we usually talk about "method"s when we want to refer to a function in class component, like lifecycle methods.

Otherwise, it's just a normal function (arrow function included).

Don't get confused between the terms function and function component as they are not the same.

Dennis Vash
  • 50,196
  • 9
  • 100
  • 118
0

Seems like they're the same thing. Here's my conjecture for why people use both: In class-based object oriented programming, the term "function" doesn't exist. Only "method". a public method, a private method, getter vs setter methods, etc.

In Javascript, the same concept has always been known as "function".

Javascript isn't originally a class-based object oriented programming language, although there are ways to make it that way. React, makes JS a class-based OOP.

So people who use the term "function" adopt a language that used to have "functions" but is now suddenly a class based object-oriented language in which you're supposed to have "methods", and the writers of the docs aren't opinionated and meticulous enough to set a standard, so they use both terms interchangeably and it leads to this confusion.