I have the following block of code:
const UserNotification = ({ user }) => {
const url = `https://api.thingspeak.com/channels/${user.channel}/feeds.json?&dynamic=true`;
console.log(url); //https://api.thingspeak.com/channels/594944/feeds.json?&dynamic=true OK
return <UserNoti url = { url } />
}
class UserNoti extends Component {
constructor(props) {
super(props);
this.state = {
items: [],
isLoaded: false,
};
}
componentDidMount() {
fetch(url)
.then(res => res.json())
.then(json => {
this.setState({
isLoaded: true,
items: json,
});
});
}
render() {...}}
However, I get a 'url' is not defined no-undef for the following line: fetch(url) in componentDidMount(). How can I call url variable inside componentDidMount method?