Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
¿Cómo limpiar el estado en el cambio de pantalla? (Usando representación condicional)

Lo que estoy tratando de hacer es limpiar un estado de mis accesorios de objetos en mi componente de clase en el cambio de pantalla

aquí es donde estoy representando los campos:

 class InputBody extends Component { constructor(props) { super(props); this.state = { fields: JSON.parse(this.props.route).message, }; } render() { return ( <Fragment> {Object.keys(JSON.parse(this.props.route).message).length > 0 ? ( <FieldArraysForm all={JSON.parse(this.props.route).message} native={this.props} /> ) : ( <ActivityIndicator size="large" color="#eb6b09" /> )} </Fragment> ); } }

Luego estoy manejando mis campos y tipos de entrada aquí:

 class RenderField extends Component { render() { return ( <Fragment> <Texto>{this.props.label}</Texto> <TextInput onChangeText={this.props.input.onChange} {...this.props.input} keyboardType={this.props.type} /> </Fragment> ); } }

Y finalmente obtengo los valores:

 class FieldArraysForm extends Component { render() { const {handleSubmit} = this.props.native; // event listener const getFields = async (values) => { return sleep(500).then(() => { // implementar prop.reset() as soon as I leave the screen, but how can I make it ? console.log(JSON.stringify(values)) }) } return ( <Form> {this.props.all.map((item) => ( <Field key={item._id} name={`customInput.${item._id}`} component={RenderField} label={item.field} type={item.typeFieldAltText} /> ))} <View> <TouchableOpacity onPress={handleSubmit(getFields)}> <Text>Save Form</Text> </TouchableOpacity> </View> </Form> ); } }

Alguien sabe cómo puedo limpiar mi estado en class component .

Obs: estoy usando: react-navigation v6 .

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Realice una función de reinicio en su componente InputBody y pase esa función como accesorio a su componente FieldArrayForm.

 class InputBody extends Component { constructor(props) { super(props); this.state = { fields: JSON.parse(this.props.route).message, }; } reset () { this.setState({}); } render() { return ( <Fragment> {Object.keys(JSON.parse(this.props.route).message).length > 0 ? ( <FieldArraysForm all={JSON.parse(this.props.route).message} resetForm={reset} native={this.props} /> ) : ( <ActivityIndicator size="large" color="#eb6b09" /> )} </Fragment> ); } }

Luego llame a los accesorios de reinicio en su componente FieldArraysForm

 const getFields = async (values) => { return sleep(500).then(() => { // implementar prop.reset() as soon as I leave the screen, but how can I make it ? console.log(JSON.stringify(values)) this.props.reset() }) }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!