-
Notifications
You must be signed in to change notification settings - Fork 27
Closed
Description
How do I add fetchData on Functional components? I get undefined on instance visitor function.
This works.
class Home extends React.Component<SampleProps> {
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
constructor(props: SampleProps) {
super(props);
}
fetchData = function () {
console.log("Home -> fetchData -> fetchData", this);
return fetch("https://google.se");
};
render() {
return <h1>Hello, {this.props.name}</h1>;
}
}
but this doesnt
const Home = (props) => {
return <h1>Hello, {props.name}</h1>;
};
Home.fetchData = function () {
console.log("Home -> fetchData -> fetchData", this);
return fetch("https://google.se");
};
any clue why?
Metadata
Metadata
Assignees
Labels
No labels