What to do if react+maxlength does not take effect

藏色散人
Release: 2022-12-30 14:08:08
Original
2700 people have browsed it

The solution for react maxlength not taking effect: 1. Open the corresponding react file; 2. Change "maxlength" to "maxLength", the code is like "".

What to do if react+maxlength does not take effect

The operating environment of this tutorial: Windows 10 system, react18.0.0 version, Dell G3 computer.

What should I do if react maxlength does not take effect?

Problem description:

I have a React input, but maxlength doesn't work. Does anyone know how to solve this problem?

This is handleChangeInput

handleChangeInput(input) {    this.setState({
        ...this.state,        form: {
            ...this.state.form,
            [input.target.name]: input.target.value
        }
    })
}
Copy after login

This is my opinion:

<div className="input-field col s12 m6 l6">
    <input onChange={this.handleChangeInput} value={this.state.form.message} type="text" className="phone validate" name="phone" maxlength="11"/>
    <label for="telefone">Telefone</label>
</div>
Copy after login

Problem solution:

Change maxlength into maxLength! Note the capital L.

<input
    id="ZIPCode"
    className="form-control"
    type="text"
    maxLength={10} // this is the important line
></input>
Copy after login

React uses camelCased html attribute, so maxlength will be maxLength.

Recommended learning: "react video tutorial"

The above is the detailed content of What to do if react+maxlength does not take effect. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!