score:3
Accepted answer
you can do:
comp.proptypes = {
lastpalletbagcount: proptypes.oneoftype([
proptypes.number,
proptypes.oneof([''])
]).isrequired
}
score:0
i think,
const [lastpalletbagcount, setlastpalletbagcount] = react.usestate<number>();
const handler = (e: any) => {
console.log(e.target.value)
const numberregex = /^[0-9\b]+$/;
if (numberregex.test(e.target.value)) {
var val = number(e.target.value);
setlastpalletbagcount(val);
}
}
return (
<input
type={'text'}
classname={'bag-count'}
value={lastpalletbagcount}
onchange={(e) =>
handler(e)
}
/>
);
would work for you.
but you would have to change the value in event in the onchange to number with some logic , because your input type is string and would return a value of type string.
Source: stackoverflow.com
Related Query
- ReactJS - number only input with PropType set to number but gets initialized to zero
- ReactJS component PropTypes - specify a function type with a set number parameters
- How to set a defaultChecked to only first input in radio button when using map function in reactjs
- reactjs - Input defaultValue is set but not showing
- ReactJS set min and max value for number input using final-form-material-ui
- Want number to limit only up to 2 digit along with upto 7 decimal point- ReactJS
- trying to display the input values but nothing shows up with no error in console reactjs
- componentdidmount does not empty the input field but only after page refresh it gets removed
- Validate input with only number and decimal after dot
- Edit an input tag with type number and onInputChange is only executed when enter is hit
- Limit content editable table data input to only one number with one decimal
- Cannot send only the filled input with axios on Reactjs
- ReactJS SyntheticEvent stopPropagation() only works with React events?
- Only numbers. Input number in React
- ReactJS can't set state from an event with event.persist()
- Initializing React number input control with blank value?
- propType [name] is not required, but has no corresponding defaultProps declaration ReactJS
- Set text input placeholder color in reactjs
- ReactJs prevent e and dot in an input type number
- React: Number input with no negative, decimal, or zero value values
- Number with decimal input in React?
- How to limit the text filed length with input type number in React JS and prevent entry of E,e, -, + etc
- How to make React input onChange set state only after onChange stops firing for set time?
- Using an input field with onBlur and a value from state blocks input in Reactjs JSX?
- How to Remove Arrow on Input type Number with Tailwind CSS
- React Formik does not work with number input
- How can I use a placeholder with a number input in React?
- How to set defaultValue, value={this.props.value}, and update the value of a text input with React?
- ReactJS - Cannot restrict user input to letters only
- react-router connected to redux : works with links but only the URL change when dispatching push
More Query from same tag
- How to deal with server responses which arrive in wrong order in react frontend?
- How to import a script for my project ? ReactJS
- Passing the state of a Child component to a Parent?
- npm peerDependencies React : can't install any packages
- dynamic routing with reactjs not working
- How to create React hooks that forward dependencies
- Problems running MERN tests
- Not able to set ShadowColor in react-native android
- Reducer state lost after history.push()
- Restrict year value to 4 digit in react js input
- how navigate using the MenuItem? material-ui V1
- modify specific redux-form value from custom function callback in react-admin
- How generic TS works in this instance
- Filter and assign object from an array to another object
- react: how to get data from redux store in a rendered component?
- use ! in Reactjs Component in JSX
- firebase data not being updated with use effect
- I am not able to add user input to state properly, getting map not a function error when it is
- How to set view of map for new location using latitute and longitude with React-leaflet
- Handling undefined/null properties in components during first render
- Webpack v4 creating tiny chunks (by route)
- React use ref to scroll to a specific component when click on link
- How to place an image folder in a react app for production/development
- How to update state with input values
- useReducer is not updating the sate with useEffect
- React Prop does not have value, cannot console log
- How to update an object of json in Reactjs
- Clear Select component after an option is selected in Ant Design and React
- How to fix 'Error: FIRESTORE (4.8.0) INTERNAL ASSERTION FAILED: Unknown relation: array-contains'
- Facebook React: Invariant Violation and elements than didn't mount automatically