With React Hooks
Just to add to Shivam's answer, here is the version with hooks:
import React, { useState } from 'react'
export default function MyTextInput(props) {
const [height, setHeight] = useState(42)
return setHeight(e.nativeEvent.contentSize.height)} />
}