0

I trying to view status of a variable (salesforecasting) in database. Its responds by sending true or false which is received fine in Postman. However when it gets to react, it is shows undefined on console. if i see whole response object, there i can see value has return correctly but when i try to print it, it shows undefined.

in routes/api/salesforecasting.js

router.post('/view', function(req, res) {
    const email="[email protected]"
    Customer.findOne({Email:email})
    .then(data=>{
        if(data){
            let salevalue=data.Salesforecasting
        res.send({
            value: salevalue 
        });
    }
    });
});

in react file

componentDidMount(){
            return axios.post('http://localhost:3000/api/sales-forecasting/view')
            .then(response => {
                //const output = response.value
                const value = response.value;
                {console.log(arr.value)}
                this.setState({
                    added: value
                });
            });
    }

1 Answer 1

2

I think u need to check in response.data.value instead of response.value. axios populates the entire server response in response.data

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.