i have a classic functionnal component returning what will be rendered in JSX
function Search(){
const loadFilms = function (){
console.log(this)); // logs undefined
};
return(
<View style= {styleAreas.view}>
<TextInput style= {styleAreas.textinput} placeholder='Type your movie ' />
<Button title='Search' onPress= {()=> { console.log(this);loadFilms();} } /> // logs undefined
<FlatList
data={films}
keyExtractor = {item => item.id.toString()}
renderItem={({item}) => <FilmItem filmDesc = {item} />}
/>
</View>
)
}
so i'm learning JS / React, and what i don't understand why this is undefined but when we run it since Class Search extends React.Component {}. it returns the right instance. especially that i tought that in JS ( i'm maybe over simplifying) a class is a function with pre-configured prototypes etc...
thank you for your explanations :)
isReactComponent
property which is only present if you inherit fromReact.Component
.