【发布时间】:2020-02-16 15:15:08
【问题描述】:
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));
}
}, []);
如何在功能组件中映射数组?我想从上面的功能组件映射治疗师数组。 React 建议我使用 UseRef(),因为我有一个功能组件并且我正在使用钩子,但我不清楚。 我从数据库中调用数组中的治疗师,我需要将它们映射到功能组件内的卡片中呈现。现在我可以访问数组元素,但我需要访问对象的一些特定参数。你们能帮帮我吗?
const renderTherapists = (props) => {
const items = props.therapists.map( (t, idx) => (
<TherapistCard therapist={t} key={idx} />
))
return (
<div ref={0} className="therapist-list">
{ items }
</div>
)
}
【问题讨论】:
标签: arrays reactjs react-hooks