Fellow Stranger Fellow Stranger - 6 months ago 14
React JSX Question

How should functions be written within a React class?

I'm trying to adapt code from a SO answer, with functions and variables written as below:

const getIntervals = n=> availability=> {

let availability = [

Are those normally fine to use in a react class (see below) or do they need to be rewritten?

class Calendar extends React.Component {}

The reason for asking is that I use a React implementation for Rails and do get an error including that function and variable naming pattern.


If you are using class and extending Component, you can use simple methods for most things:

class Calendar extends React.Component {
  constructor(props) {
    this.date = props.date;

  render() {
    return <span>{this.date.toString()}</span>;

Calendar.propTypes = {
  date: React.PropTypes.date.isRequired

You cannot use methods for propTypes or anything that would be an initial field if you were using an object literal. Those need to be attached after the class has been declared (propTypes) or in the constructor (initial state).