Giter Club home page Giter Club logo

Comments (3)

srivastavaanurag79 avatar srivastavaanurag79 commented on August 17, 2024

Can you please share your code snippet if possible, and please elaborate on your issue.

I think what you want to do after API call is:

const rd = []; response.data.data.map((data) => { rd.push({ _id: data.id.toString(), value: data.employee, }); });

setReporting({...reporting, list:rd});

assuming your useState hook is declared like this:
const [reporting, setReporting] = useState({ value: '', list: [], selectedList: [], error: '', });

Make a copy using spread operator and update only those values you want using setState.

Please refer to this link: Example Code, API call is mimicked in line no. 46 useEffect

from react-native-paper-select.

Centeos avatar Centeos commented on August 17, 2024

Hi, Thanks for replying on this,

Actually i want to replace the complete value of list after api call.

Please check the below code what i have used.

const [reporting, setReporting] = useState({
    value: '',
    list: [],
    selectedList: [],
    error: '',
  });

  const FetchReportingEmployee = () => {
    console.log("start reporting");
    let params = {
      AddedByUserID: userID,
    };
    Provider.getAll(`master/getreportingemployeelist?${new URLSearchParams(params)}`)
      .then((response) => {
        if (response.data && response.data.code === 200) {
          if (response.data.data) {
            const rd = [];
            response.data.data.map((data) => {
              rd.push({
                _id: data.id.toString(),
                value: data.employee,
              });
            });
           
            setReporting({
              list:rd,
              value: value.text,
              selectedList: value.selectedList,
              error: '',
            });

            console.log(reporting.list);

            setReportingFullData(rd);
          }
        }
      })
      .catch((e) => { });
  };

from react-native-paper-select.

srivastavaanurag79 avatar srivastavaanurag79 commented on August 17, 2024

I think this would update your list:

use

setReporting({...reporting, list: rd});

instead of

setReporting({
 list:rd,
 value: value.text,
 selectedList: value.selectedList,
 error: '',
});

please refer to this guide: useState in React: A complete guide for a better understanding of React's useState hook.

your code should look like this:

const [reporting, setReporting] = useState({
    value: '',
    list: [],
    selectedList: [],
    error: '',
  });

  const FetchReportingEmployee = () => {
    console.log("start reporting");
    let params = {
      AddedByUserID: userID,
    };
    Provider.getAll(`master/getreportingemployeelist?${new URLSearchParams(params)}`)
      .then((response) => {
        if (response.data && response.data.code === 200) {
          if (response.data.data) {
            const rd = [];
            response.data.data.map((data) => {
              rd.push({
                _id: data.id.toString(),
                value: data.employee,
              });
            });
           
            setReporting({...reporting, list: rd});

            console.log(reporting.list);
          }
        }
      })
      .catch((e) => { });
  };

from react-native-paper-select.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.