I want to console log the value of a variable belonging to the component inside useState, but it keeps console logging 'null' right after I set it. Is there like a "getState"-function? Before upgrading to latest react with hooks I could access the variables with this.state.variableName.
Thanks a lot guys!
const DriverHome = (props) => {
const [bookings, setBookings] = useState([]);
useEffect(() => {
if (!user) {
props.history.push('/login');
}
socket.on('booking updated', (message, booking) => {
getAllDriverBookings(user.email)
.then((b) => {
setBookings(b.data.bookings);
playSound();
})
.then(console.log('bookings:', bookings));
});
When i try to print bookings, it keeps printing null even though it's not.