Reactjs 单击按钮时如何查看其他用户信息?
在下面的函数中,有一个用户的信息是“temp_id”。单击按钮时,我想将此“临时id”传递到下面的文件Reactjs 单击按钮时如何查看其他用户信息?,reactjs,Reactjs,在下面的函数中,有一个用户的信息是“temp_id”。单击按钮时,我想将此“临时id”传递到下面的文件 const temp_id = { description: 'Lorem Ipsum is simply dummy text of the printin...', email: 'xxx@gmail.com', name: 'john', private: false, rating: 0,
const temp_id = {
description: 'Lorem Ipsum is simply dummy text of the printin...',
email: 'xxx@gmail.com',
name: 'john',
private: false,
rating: 0,
role: 'PATIENT',
status: 'Face with Tears of Joy',
surname: 'cash',
username: 'kibitzer',
};
const TestMeetingCreate = props => {
return (
<div>
<button onClick={temp_id}>
{' '}
<Link to={ROUTES.PROFILE}>Go to profile</Link>
</button>
</div>
);
};
const temp\u id={
描述:“Lorem Ipsum只是printin…”的虚拟文本,
电邮:'xxx@gmail.com',
姓名:'约翰',
二等兵:错,
评级:0,
角色:'患者',
状态:“脸上挂着喜悦的泪水”,
姓:“现金”,
用户名:“kibitzer”,
};
const TestMeetingCreate=props=>{
返回(
{' '}
转到个人资料
);
};
当我从导航中单击PersonalInfo页面时,我可以看到我从firebase获得的“用户”的所有信息,这是正常的。但是我想要的是,如果我从上面的页面访问这个页面,我想看到临时id的数据。我在常量中定义了“temp_id”,但无法通过这种方式访问它。当我点击按钮时,“temp_id”仍然为空,因此它显示“用户”数据。我怎样才能解决这个问题
const PersonalInfo = props => {
const { user, openSettings, temp_id } = props;
return !temp_id ? (
<div className="col-lg-3 col-md-3 col-sm-12 col-12 pl-5 pr-5 pt-2 pb-4 profile-info">
<div className="row mt-2">
<span>{`${user.name} ${user.surname}`}</span>
</div>
<div className="row mt-2 h-auto">
<span>{`${user.description}`}</span>
</div>
<div className="row mt-3">
<button
className="btn btn-secondary btn-block"
type="button"
onClick={openSettings}
>
Profili Düzenle
</button>
</div>
<div className="row mt-2">
<div className="col-12">
<div className="col-12 no-padding">
<span className="align-middle">{` ${user.email}`}</span>
</div>
</div>
</div>
</div>
) : (
<div className="col-lg-3 col-md-3 col-sm-12 col-12 pl-5 pr-5 pt-2 pb-4 profile-info">
<div className="row mt-2">
<div className="col-lg-9 col-9">
<div className="row font-18 font-weight-bold">
<span>{`${temp_id.name} ${temp_id.surname}`}</span>
</div>
<div className="row font-weight-lighter font-italic">
<span>{`${temp_id.username}`}</span>
</div>
</div>
</div>
<div className="row mt-2 h-auto">
<span>{`${temp_id.description}`}</span>
</div>
<div className="row mt-2">
<span className="align-middle">{` ${temp_id.email}`}</span>
</div>
</div>
</div>
);
};
constpersonalinfo=props=>{
const{user,openSettings,temp_id}=props;
返回!临时身份证(
{`${user.name}${user.name}`}
{`${user.description}`}
杜泽勒
{`${user.email}`}
) : (
{`${temp\u id.name}${temp\u id.name}`}
{`${temp\u id.username}`}
{`${temp\u id.description}`}
{`${temp\u id.email}`}
);
};
您可以使用重定向
而不是链接
来实现这一点。由于您使用的是按钮单击,我建议您使用所需的值设置按钮单击的状态
然后使用下面的语法
<Redirect
to={{
pathname: "/login",
state: { temp_id: [your value or variable] }
}}
/>
注意:您需要使用路由器将组件包装在中,或者使用路由器挂钩访问位置对象
this.props.location.state.temp_id