What I'm trying to do is to pass an id of a client to the parent component when the user selects a client.
In the child component, I receive the data with Axios, and I put the data in the <Listbox />
so the user can select it.
Select.js
export default function SelectPlayer() {
const [client, setClient] = useState([])
const [selected, setSelected] = useState(client[0])
useEffect(() => {
const params =
"userName=" +
currentUser +
setClient([]);
axios
.get(API + params)
.then((response) => {
const { data } = response;
setClient(data);
})
.catch((error) => console.log(error.message));
}, []);
return(
<Listbox value={selected} onChange={setSelected}>
{({ open }) => (
<>
<Listbox.Label>Select a Player:</Listbox.Label>
<div">
<Listbox.Button>
{selected != undefined ? <span>{selected.client_name}</span> : 'Select'}
</Listbox.Button>
<Listbox />
);
How can I pass selected.client_id
to another component?