2

First of all, I have a basic level in english. So I hope you understand.

Is the rerender of a child component in react native different in react? Let me give you an example:

class App extends React.Component{

 constructor(props) {
    super(props);

  }

 render(){
    return(
        <ChildComponent />
    )
  }

  componentDidMount() {
    this.setState({test:'test'})
  }

}    

this in react rerender ChildComponent once, but in React Native ChildComponent not rerender only have your initial render. Why?

ps: ChildComponent have just a div in React and Text in React Native.

pedrohpinho
  • 63
  • 1
  • 4
  • You mean you can't see the text in ChildComponent on React-native? – hong developer Sep 12 '19 at 14:59
  • I can. but if I put a console.log('test') in render method of ChildComponent, on react i see 'teste' twice and on react native once. The deubt is not the text shown, but the amount of times that method render of the ChildComponent is called. – pedrohpinho Sep 12 '19 at 15:41

1 Answers1

0

No in react and react native both rendering the child component is same. Let us take an example

Parent.js

import React, { Component } from 'react';
import { Text, View } from 'react-native'
import Child from './Child'

export default class Parent extends Component {
    render() {
        return (
            <View>
                <Text> Hi I am a parent component </Text>
                <Child/>
            </View>
        )
    }
}

Child.js

import React, { Component } from 'react'
import { Text, View } from 'react-native'

export default class Child extends Component {
    render() {
        return (
            <View>
                <Text> This is child </Text>
            </View>
        )
    }
}
Vikas chhabra
  • 281
  • 1
  • 8