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
Appcomponent will receive all the props as properties of an object that will be passed as an argument, commonly referred to aspropsobject. You need to destructure thepropsobject to access the token and other propsAlternatively, you could use the
propsobject instead of destructuring itand then use
props.tokenandprops.requestTokento access the props as properties ofpropsobject.