I have written a method like below but i am noticing my API is getting called multiple times. I am calling my API inside componentDidMount().
class User extends Component {
state = {
cardData: [],
};
userDetails = async () => {
const data = await fetchUserDetails();
if (data) {
const url = data.baseUrl;
const getDetails = Object.values(data).map((users) => users.user);
this.setState({ cardData: getDetails });
}
};
componentDidMount() {
this.userDetails();
}
}
How can i overcome this?