How to return to const method

Hi, I'm new to being so sorry for the main question.

I am trying to define a method in const

const Age = t.refinement(t.Number, (n) => return n >= 18);

However, linter doesn't like that I have a return keyword in a method. Here is the class

import React, { Component } from 'react'
import { postFeedback } from 'Services/Config'
import { render } from 'react-dom';
import t from 'tcomb-form';


const FormSchema = t.struct({
    name: t.String,         // a required string
    age: t.Number, // an optional number
    rememberMe: t.Boolean   // a boolean
})

const Age = t.refinement(t.Number, (n) => return n >= 18);

export class Form extends Component {

onSubmit = (evt) => {
    evt.preventDefault()
    const value = this.refs.form.getValue()
    console.log(value)
    console.log("validation ->   " + this.refs.form.validate())
    if (value) {
        console.log(value)
    }
}

render() {
    return (
        <form onSubmit={this.onSubmit}>
            <t.form.Form ref="form" type={FormSchema} />
            <div className="form-group">
                <button type="submit" className="btn btn-primary">Save</button>
            </div>
        </form>
    )
}

}


export default Form
+4
source share
1 answer

This is an anonymous function of ES2015 Arrow , it is not associated with the keyword const.
Arrow functions are returned implicitly or explicitly, it depends if you use the body block of the function {}.

Or do this (explicit return):

const Age = t.refinement(t.Number, (n) => {return n >= 18});

Or do it (implicit return):

const Age = t.refinement(t.Number, (n) => n >= 18);
+5
source

Source: https://habr.com/ru/post/1691177/


All Articles