Why does input in React/Redux form change a number into a string?

Why does input in React/Redux form change a number into a string?

Content Index :

Why does input in React/Redux form change a number into a string?
Tag : reactjs , By : Bart van Bragt
Date : November 29 2020, 01:01 AM

I hope this helps . Input values are always sent to you as Strings, no matter the input type. When you use input type=“number” it only helps the browser to present a number keypad for example.
You either have to cast the value to Int (parseInt) before calling your action or inside the action itself.

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

React.js Redux: unwanted change of redux store on input handling

Tag : javascript , By : hyperNURb
Date : March 29 2020, 07:55 AM
Hope that helps Alright. There is a reference into the store and to change that a deep copy is needed as the strucutre and fields of showLayer are not known beforehand and can vary depending the type of layer.
Using either this JSON.parse(JSON.stringify(this.state.showLayer)) in the handleChange()function or JSON.parse(JSON.stringify(state.availableLayers.toObject)) in mapStateToProps() resolves the issue.

React Redux form input editing returns error message of an uncontrolled input

Tag : reactjs , By : Al Dimond
Date : March 29 2020, 07:55 AM
To fix this issue At last what solve my problem of input form not editing was replacing form input value{} with defaultValue{} option. I leverage solutions/answer posted by Solanki here React Input Type not editable
Not this anymore
<input type="text" className="form-control" value={pgs1.items1 && this.props.pgs1.items1[0].lastName}  onChange={this.handleChange}/>  
<input type="text" className="form-control" defaultValue={pgs1.items1 && this.props.pgs1.items1[0].lastName}  onChange={this.handleChange}/>  

React Redux - Display string stored in Redux state within Input field

Tag : javascript , By : KT.
Date : March 29 2020, 07:55 AM
will help you You can change/add value to input element using ref. ref will basically have the reference of actual dom node, so by changing this.refName.current.value will change the input value.
But you need to do it after initial rending, means after ref get the reference of input element.
class App extends React.Component {

  constructor() {
    this.a = React.createRef();
  click = () => {
    this.a.current.value = Math.floor(Math.random()*100);
  render() {
    return (
        <input ref={this.a} placeholder="Number" />
        <button onClick={this.click}>Click here to change the input value</button>

ReactDOM.render(<App />, document.getElementById('app'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

<div id='app' />

Value on Input didnt change when state change on React + Redux

Tag : javascript , By : ranja
Date : March 29 2020, 07:55 AM
Hope that helps Here is a example of a full controlled input.
const Input = () =>{
    const [value, setValue] = useState('')
        <input value={value} onChange={e => setValue(e.target.value)} />
class Input extends React.Component{
    state ={ value: ''}
    onChangeHandler = e => this.setState({value: e.target.value})

            <input value={this.state.value} onChange={this.onChangeHandler} />

Form input not changing when using react-testing-library on redux-form

Tag : reactjs , By : user133834
Date : March 29 2020, 07:55 AM
it fixes the issue Since you are not using the reducer from redux-form in your tests, its props will not be passed down to your component correctly. It's best if you provide a reducer which resembles what your app is actually using. The following code works.
import React from "react"
import { Provider } from "react-redux"
import { combineReducers, createStore } from "redux"
import { reducer as reduxFormReducer } from "redux-form"
import { fireEvent, render } from "@testing-library/react"
import SimpleForm from "./SimpleForm"

// Create a reducer that includes the form reducer from redux-form
const reducer = combineReducers({
  form: reduxFormReducer,

const store = createStore(reducer)

it("test that button is not disabled when input is entered", () => {
  const { getByLabelText, getByText } = render(
    <Provider store={store}>
      <SimpleForm />

  const input = getByLabelText("Name")
  const submit = getByText("Submit")

  fireEvent.change(input, { target: { value: "test input" } })


Related Posts Related QUESTIONS :
  • Dropping files or opening files from the file selector dialog box causes the React component to unmount
  • How to check if a component has been clicked after an onblur event in React
  • What should be considered as component in React
  • Updating Parents state from Child without triggering a rerender of Child in React
  • Select component is ignoring parent onClick event
  • How to add Condition inside render method in reactjs
  • How to fix form that will not allow text to be entered?
  • Cannot read property 'name' of undefined on React with my props
  • Material UI tooltip doesn't display on custom component, despite spreading props to that component
  • Unexpected output but expected view when using hooks React for toggle
  • Determine if two objects have an identical structure with Jest
  • Material ui - snackbox aria label not being read
  • Why is useState hook calling initialising value code twice?
  • React - override state by exists object properties
  • how to stop re-rendering of list items in context consumer when state changes
  • how to pass props one page to another page via react router?
  • How to display react numerical props only if they pass from the container?
  • Input in another component, error with target
  • What is the difference between props and children in Gatsby?
  • Validating conditional pairs of props with Typescript
  • React-Dropzone how convert each file to base64
  • How to change the return of a function to int?
  • Import only grid system from bootstrap to react
  • TypeScript Type for function arguments not erroring?
  • Unexpected user of comma operator no-sequences
  • React Native onChangeText like onChange in ReactJS
  • How to dynamically render an element on clicking a button
  • Cannot import components from react-bootstrap
  • How to prevent Office UI Fabric React DatePicker flyout from stealing focus when allowTextInput is true?
  • How delete item from redux state?
  • Uncaught TypeError: map is not a function In Reactjs with Firebase
  • Alternative to componentWillReceiveProps for my particular use case
  • Pokemon, API call Variable doesn't save
  • Rendered more hooks than during the previous render. when posting form data with React Hooks
  • How can I envoke <Link to=''> route transition from a custom function?
  • How to change certain div color base on number
  • Hide Navbar on some routes (React Router v5)
  • is it safe to ignore react's warning about calling the useState hook conditionally when only the parameter is conditiona
  • How to pass a function as a prop to React function component?
  • Creating a function that replace a letter with a line break
  • How to add and remove property from Redux state
  • Can I, (and should I), make assertions about what HTML elements a component renders using Enzyme's shallow()?
  • Testing function calls in Jest after button click (mocking fetch calls)
  • How can I show a card shadow on all sides?
  • Jest - Map through an Array of Items and test their Values
  • Run Effect hook only when both dependencies change
  • What is the difference between .ts and .tsx extensions. Both are used as extensions for typescript files in react. So wh
  • Font size of tooltip in speeddialaction of React's Material UI
  • Module Not Found - Webpack Dev Server
  • React not rendering all elements within a list of components
  • How to change attribute of a React Element
  • ReactJs: How to back focus to input field after resetting the form
  • Multilanguage in react using redux
  • React JS — how do I add child components and set calculated transformations?
  • ReactJS componentDidUpdate() prevState equals to currentState
  • TypeScript error: JSX element type 'Tree' does not have any construct or call signatures. I'm not able to import my own
  • createProvider is not exported from react-redux?
  • Error:(19, 35) TS2304: Cannot find name 'T'. Why I can't extend interface in TS?
  • How can I secure images in S3 buckets with Auth0 and a React front-end
  • React Import Multiple Functions
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com