【发布时间】:2021-07-18 07:51:00
【问题描述】:
嘿,我是新来的反应和自学成才的人。有人可以指出我正确的方向或给我一些线索。我的页面顶部显示了一个反应选择组件。此组件中的数据是从我的 useContext 提供程序中填充的。我想要的结果是,当用户选择某个组件时,我想用具有相应数据的相关卡片填充页面。所有数据都在我的 authContext 中可用。
我已经走到了这一步,但是当用户从下拉列表中选择值时,什么都没有填充。有人可以帮忙吗:-
import React, { useContext, useEffect, useState } from 'react'
import styles from './FullRecord.module.css'
import {AuthContext} from '../../shared/context/auth-context'
import Select from 'react-select'
import { makeStyles } from '@material-ui/core/styles';
import Card from '@material-ui/core/Card';
import CardContent from '@material-ui/core/CardContent';
import Typography from '@material-ui/core/Typography';
const useStyles = makeStyles({
custom: {
backgroundColor: "#558d6b",
fontWeight: "bold"
},
customFont: {
fontWeight: "bold",
fontSize: "20px"
},
customFont1: {
fontWeight: "light"
}
});
const FullRecord = (props) => {
let data
const auth = useContext(AuthContext)
const [edition1, setEdition1] = useState(false)
const options = auth.tournaments.map((tournament) => {
return {
value: tournament.TournamentName,
label: tournament.TournamentName,
}
})
console.log(options)
const classes = useStyles();
const handleChange = (selectedValue1) => {
console.log(selectedValue1)
setEdition1(true)
const {value} = selectedValue1
console.log(value)
console.log(edition1)
if(value === 'GSM Edition 1'){
const noOfMatches = auth.profile.MemberMatches.filter((match) => match.TournamentName === 'GSM Edition 1')
console.log(noOfMatches)
data =
<div>
<li className={styles['member-item']}>
<Card className={classes.custom} variant="outlined">
<CardContent>
<Typography className={classes.customFont} gutterBottom>
Number Of Matches Played
</Typography>
<Typography className={classes.customFont}>
{noOfMatches}
</Typography>
</CardContent>
</Card>
</li>
</div>
}
}
return (
<React.Fragment>
<div className={styles['fullrecord__maindiv']}>
<Select
// value={options.value}
onChange={handleChange}
options={options}
/>
</div>
{edition1 && <div>
{data}
</div>}
</React.Fragment>
)
}
export default FullRecord
【问题讨论】:
标签: reactjs react-select