A
A
antonstolar2019-08-09 12:45:53
React
antonstolar, 2019-08-09 12:45:53

Is it possible to combine regular functions with an ES6 class in React?

First question:
In React, functions are written like this:

showName: function () {

}

Is it possible to write a function like in JS? like this:
function showName () {

}

Will there be an error? Or is it considered good manners to write down the name of the function first, then the colon, and then the function keyword , so that, for example, other programmers can see that this is React code? Or how?
And the second question:
It is possible to combine the usual React functions:
showName: function () {

}

with ES6 class:
class Name extends Component {
}

instead of:
var Name=React.createClass {
}

Like this:
class Name extends Component {
showName: function () {
//....
}
}

Or so wrong?
I don't like simple arrow functions...

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Anton Spirin, 2019-08-09
@antonstolar

learn.javascript.ru Learn everything
if possible. It's too early for you to take on React yet. All your questions are based on ignorance of JavaScript.

H
harutyunyan, 2019-08-09
@harutyunyan

If it's a component then write like this

function SomethingComponent () {

}

In a class, declare a function like this
showName () {

}

Arrow functions are ES6 if anything...

M
mrxakerrus, 2017-12-21
@mrxakerrus

1) In the if statement, you are trying to ASSIGN A VALUE, NOT COMPARE
2) You need to call the properties of the element through GetComputedStyle or through style

R
retyui, 2017-12-22
@retyui

Try it

function AdaptiveMenu() {
  var Adaptive = document.getElementById('adaptiveNavbar');
  var AdaptiveStyle = getComputedStyle(Adaptive);
  if (AdaptiveStyle.display === 'none') {
    Adaptive.style.display = 'block';
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question