The code is related to singly linked list,I am trying to display a value of a singly linked list using map function and state in react js.
the function logic() is to update state when display button clicks,all values in linked list is stored in an array, it update state listdata but the problems is when display button clicks then map function is not called....
to solve above issue please suggest some idea,tips about it....
The code is :-
import { useState } from "react"
import { Container } from "react-bootstrap"
import "./css/style.css"
const logic = (start) => {
let temp = start.props
let arr = []
let k = 0
while(temp.ptr!=null) {
arr[k] = temp.n
k++
temp=temp.ptr
}
arr[k]=temp.n
return arr
}
const SDisplay = (start,setdisp) => {
const [ listdata,setlistdata ] = useState([])
return (
<>
<Container>
<input type="button" onClick={()=>{setlistdata([...logic(start)])}} value="Display"></input>
{
listdata.map((i)=>{
<div className="d-flex align-items-center">
<div className="box">{i}</div>
<div className="arrow"></div>
</div>
})
}
<a href="#" onClick={()=>{setdisp.display(false)}} className="text-decoration-none text-dark">Back</a>
</Container>
</>
)
}
export default SDisplay