Home > Blockchain >  Why can't access my new state value from another function in react.js hook?
Why can't access my new state value from another function in react.js hook?

Time:03-21

I set my marinaList new value. I can access marinaList state in GetMarinaList function. But when I try access marinaList state in GetCounterConnectionDevices function I get inital value of marinaList. Why I can't access my current value of my state in another function ?

import React, { useState, useCallback, useEffect } from "react";

function CounterConnectionDeviceDefinition(props) {
    const [marinaList, setMarinaList] = useState([]);
    useEffect(() => {
        GetMarinaList();
    }, [])
    const GetMarinaList = () => {
        const RETRIEVED_MARINAS = [
            {
                "Oid": 3348000013080006,
                "Status": 1,
                "LastUpdated": 1615185446387,
                "OperationRefNo": 1459738,
                "MarinaCode": 1,
                "MarinaName": "MERSİN MARİNA",
                "MarinaLocation": "MERSİN",
                "IsActive": true
            },
        ]
        setMarinaList(RETRIEVED_MARINAS)
        console.log(" RETRIEVED_MARINAS", RETRIEVED_MARINAS); //I get retrieved marina data
        GetCounterConnectionDevices(-1);
    }
    const GetCounterConnectionDevices = () => {
        const RETRIEVED_COUNTER_CONNECTION_DEVICES = [
            {
                "Oid": 3348000013898110,
                "Status": 1,
                "LastUpdated": 1618484345355,
                "OperationRefNo": 1498555,
                "PedestalControlCenterOid": 3348000013898011,
                "CounterParameterType": {
                    "Oid": 0,
                    "Status": 0,
                    "LastUpdated": 0,
                    "OperationRefNo": 0,
                    "ParameterTypeOid": 0,
                    "ParameterName": null,
                    "ParameterCode": "001",
                    "ParameterExplanation": null
                },
                "CounterConnectionDeviceModelName": "LUNA_BC62_ANTALYA",
                "CounterConnectionDeviceId": "6-0-64-228-24-0-0-0",
                "CounterConnectionDevicePassword": null,
                "CounterConnectionDeviceIpAddress": null,
                "CounterConnectionDevicePortNumber": null,
                "IsActive": true
            },
        ]
       console.log("           
  • Related