React select not showing the value which has been selected

Viewed 20

I'm using react select in my ticketing application where It should allow multiple people to assign and its working fine and I'm able to select the multiple people and they can be seen and when I comeback and open the same ticket I want to show the already assigned people in the select using value but its not working.

I did like value = {{label:ticketInfo.Assigned}} where ticketInfo is a state and I'm getting this data from Nodejs backend where assignedTo is an array of usernames that has been selected previously.Currently its showing empty even if there are assigned people

Here is the some of the code:

function MainTicket({setMenu}){

const {id} = useParams();
const navigate = useNavigate()
const [ticketInfo,setTicketInfo] =useState({

    status:'',
    Description:'',
    Solution:'',
    assignedTo:[],
    exhibitName:'',
    problemImages:[],
    solutionImages:[]

})
const [users,setUsers] =useState([])
const [userOpts,setUserOpts] = useState([]);
const [selectedusers,setSelectedusers]=useState([]);
const [message,setMessage]=useState({
    isLoading:'',
    isSuccess:'',
    isError:''
});
const [isClosed,setIsClosed]=useState(false);

useEffect(()=>{
    setMenu(false);
    let mounted = true;
    async function getTicketData(){
        try{
        const result =  await axios.get(`${SERVER_URL}/api/ticket/${id}`)
        if(result){
                console.log(result.data,result.data.ticket);
                setTicketInfo({
                    status:result.data.ticket.status,
                    Description:result.data.ticket.Description,
                    Solution:result.data.ticket.Solution,
                    assignedTo:[...result.data.ticket.assignedTo],
                    problemImages:result.data.ticket.problemImages?result.data.ticket.problemImages:[],
                    solutionImages:result.data.ticket.solutionImages?result.data.ticket.solutionImages:[],
                    exhibitName:result.data.ticket.exhibitName

                })
                if(result.data.ticket.assignedTo.length>0){
                       let  usersSelect=[];
                        result.data.ticket.assignedTo.forEach((user)=>{
                                usersSelect.push(
                                    {label:user,value:user}
                                )
                            

                        })
                        console.log(usersSelect,'fgd');
                        setSelectedusers([...usersSelect]);
                }
                result.data.ticket.status==='Closed'&&setIsClosed(true);
        }
    }
    catch(err){
        console.log(err)
    } 
Assign To:
0 Answers
Related