Good morning,
I'm new to react, and I'm trying to figure things out.
I found a spotify button which connect to the spotify API from your cliendID. It looks like this
import React from 'react';
import ReactDOM from 'react-dom';
import SpotifyLogin from 'react-spotify-login';
import { clientId, redirectUri } from './settings';
const onSuccess = response => console.log(response);
const onFailure = response => console.error(response);
ReactDOM.render(
<SpotifyLogin clientId={clientId}
redirectUri={redirectUri}
onSuccess={onSuccess}
onFailure={onFailure}/>,
document.getElementById('example')
);
The data I want to get is the response from it because it has the access_token. Being new to react, I thought I could make a class with a getter in it.
import React, { Component, setState, useState } from 'react';
import SpotifyLogin from 'react-spotify-login';
import { Link } from 'react-router-dom'
class App extends Component {
constructor() {
super()
this.state = {
onSuccess : {}
}
}
getData() {
return this.onSuccess;
}
render(){
return (
<div>
<Link to="/home">
<SpotifyLogin buttonText="Login" clientId='myinfo'
redirectUri='http://localhost:3000/home'
onSuccess={this.onSuccess}/>
</Link>
</div>
)
}
}
export default App
but in my other component, when I try to do a
var toto = new App
console.log(toto.getData);
it's all empty. Moreover, I would like to know if there's a way which will allow me to avoid the declaration of a new object inside my component each time I will need to access my data. For example, I will pass props to my classes, so if I call this component in the file where I declared an instance of App it will be ok, but what if I use this component in another file and there's no instance of App, how could I have access to this data. Is there a way to global it ?