Load the state value into the currency formatted DidMount component

Asked

Viewed 97 times

2

I want to load a value defined in state of the application. Using a lib to format the input and put Real format coin mask (react-intl-currency-input).

Only it does not load the value in the input when we apply the componentDidMount.

Look at:

this.state = {
   salario: '1800.00'
}

<IntlCurrencyInput
   currency="BRL"
   config={currencyConfig}
   onChange={this.handleChangeSalarioFormato}
   id="salario"
   value={this.props.salario}
   placeholder="Salário"
   disabled={this.state.disabled}
   className="form-control"
 />

1 answer

1


Passes the initial value on the property defaultValue of the component <IntlCurrencyInput>. Then treat the value change in your function handleChangeSalarioFormato:

<IntlCurrencyInput
   currency="BRL"
   config={currencyConfig}
   onChange={this.handleChangeSalarioFormato}
   id="salario"
   defaultValue={this.props.salario}
   placeholder="Salário"
   disabled={this.state.disabled}
   className="form-control"
 />

Browser other questions tagged

You are not signed in. Login or sign up in order to post.