import axios from "axios";
import React, {useEffect, useState} from "react";
in loginUser i get sucessfuly the username ,and redirect …but befor redirect it
const url = `https://api.agify.io`
export const loginUser = (values, history, setFieldError, setSubmitting) => {
const username = values.email.split("@")[0]
return () => {
axios.get(url,{
params:{
name:username
}
}).then((response) => {
console.log("username", username)
//here i should save username for use it globall
console.log("response", response)
history.push("/user")
}).catch(error => console.error(error))
setSubmitting(false);
}
}
i should use the user name that come from loginUser for showing it in my code on Userinfo,after getting that props save it globally,for using everywhere,
after that should work axios call
export const Userinfo = () => {
const [state, setState] = useState({info: []});
useEffect(() => {
axios
.get("https://api2.binance.com/api/v3/ticker/24hr")
.then((response) => {
setState({
info: response.data
});
console.log(response.data);
});
}, [])
const {info} = state;
return (
<div>
<h2>post!</h2>
{info.map((user) => (
<div key={user.data}>
<h6>{user.count}</h6>
</div>
))}
</div>
);
}
this code i write in redux component
here is my code
https://codesandbox.io/s/agitated-cherry-rfrj6?file=/src/auth/actions/userActions.js