In my action file I create a fetchMethod
export const requestEmbedToken = () => (dispatch) => {
return axios.get('http://localhost:7071/api/getTokens')
.then(response => {
console.log("token embed", response)
})
}
app.js
import { requestEmbedToken } from './redux/actions'
function App(token, requestToken) {
const [embedToken, setEmbedToken] = useState(token.token);
useEffect(() => {
if (token.token === undefined) {
requestToken()
setEmbedToken(token.token)
}
});
return (
const mapDispatchToProps = (dispatch) => {
return ({
requestToken: () => dispatch(requestEmbedToken())
})
}
export default connect(mapStateToProps, mapDispatchToProps)(App)
Actually I'm getting an error
TypeError: requestToken is not a function
App
component will receive all the props as properties of an object that will be passed as an argument, commonly referred to asprops
object. You need to destructure theprops
object to access the token and other propsAlternatively, you could use the
props
object instead of destructuring itand then use
props.token
andprops.requestToken
to access the props as properties ofprops
object.