Arrays 功能组件中数组的映射和对特定对象的访问
如何在功能组件中映射数组?我想从上面的功能组件映射治疗师阵列。React建议我使用UseRef(),因为我有一个功能组件,我使用的是钩子,但我不清楚。 我从数据库中调用数组中的治疗师,我需要将他们映射到一张卡片中,在一个功能组件中进行渲染。现在我可以访问数组元素,但我需要访问对象的一些特定参数。你们能帮帮我吗Arrays 功能组件中数组的映射和对特定对象的访问,arrays,reactjs,react-hooks,Arrays,Reactjs,React Hooks,如何在功能组件中映射数组?我想从上面的功能组件映射治疗师阵列。React建议我使用UseRef(),因为我有一个功能组件,我使用的是钩子,但我不清楚。 我从数据库中调用数组中的治疗师,我需要将他们映射到一张卡片中,在一个功能组件中进行渲染。现在我可以访问数组元素,但我需要访问对象的一些特定参数。你们能帮帮我吗 function TypeArticleOne(props) { let apiData = props.apiData; const [ therapists, setTherapist
function TypeArticleOne(props) {
let apiData = props.apiData;
const [ therapists, setTherapists ] = useState(apiData.topProfiles.therapists);
const [speciality, setSpeciality]= useState('ABA');
const [pageLoading, setPageLoading]= useState(true);
const topProfilesUrl = 'therapists/top/profiles'
useEffect(() => {
console.log(speciality);
getTopTherapists();
window.scrollTo(0, 0);
}, []);
const getTopTherapists = () => {
setPageLoading(true);
loadTopTherapists();
};
const loadTopTherapists = () => {
console.log("second");
props.actions.reqGetTherapistsTopProfiles({
body: {},
headers: null,
resource: `${topProfilesUrl}`
})
};
useEffect(() => {
if (apiData.topProfiles && apiData.topProfiles.success) {
const therapistsLoad = apiData.topProfiles.therapists;
setPageLoading(false);
setTherapists([therapists].concat(therapistsLoad));
}
}, []);
const renderherapists=(道具)=>{
常量项目=道具。治疗师。地图((t,idx)=>(
))
返回(
{items}
)
}
与其声明常量,不如直接映射道具,如下所示:
const renderTherapists = (props) => {
const items = props.therapists.map( (t, idx) => (
<TherapistCard therapist={t} key={idx} />
))
return (
<div ref={0} className="therapist-list">
{ items }
</div>
)
}
const renderherapists=props=>{
返回(
{props.therapists.map((t,idx)=>{
返回
})}
)
}
导出默认的renderherapists;
const RenderTherapists = props => {
return (
<div className="therapist-list">
{ props.therapists.map((t, idx) => {
return <TherapistCard therapist={t} key={idx} />
})}
</div>
)
}
export default RenderTherapists;