Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ReactJS: Allow only numbers in input in stateless non component?

Sorry, this question is maybe duplicated and answered here, but do not solve my problem.

I want to allow only numbers in my input outside return and in the nonstate component and inside props.

My code.js

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const General = props => (
    <Row>
        <Col>
            <Form.Item>
                <Input />
            </Form.Item>
        </Col>
    </Row>
)

export default General

>Solution :

try this please.

State is here.

  const [obj, setobj] = useState({ number: 0 });

onChange function is here.

  const onChangeData = (event, type, value) => {
    let data = null;
    data = value;
    setobj({ ...obj, [type]: data })
  }

input function is here.

<input 
   type="number" 
   value={obj.number}  
   onChange={(event) => this.onChangeData("number",event.target.value)} />
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading