我是react and react firestore的新手。有人能告诉我如何在firestoreconnect函数中添加路由参数吗。我的代码低于
class Exam extends Component {
state = {
id: null,
};
componentDidMount() {
let id = this.props.match.params.examId;
this.setState({
id: id,
});
}
render() {
// console.log(this.props.questions);
const { auth, questions } = this.props;
console.log(questions);
if (!auth.uid) {
return <Redirect to="/" />;
}
return (
<div className="container" style={{ width: "8 rem" }}>
<br />
<br />
<br />
<Form>
{["checkbox", "radio"].map((type) => (
<div key={`default-${type}`} className="mb-3">
<Form.Check
disabled
type={type}
label={`disabled ${type}`}
id={`disabled-default-${type}`}
/>
</div>
))}
<Button variant="primary" type="submit">
Submit
</Button>
</Form>
<h1>Exam id is {this.state.id}</h1>
</div>
);
}
}
const mapStateToProps = (state) => {
return {
auth: state.firebase.auth,
questions: state.firestore.ordered.questions,
};
};
export default compose(
connect(mapStateToProps),
firestoreConnect([
{
collection: "questions",
},
])
)(Exam);
我想添加一个";doc";firestoreConnect中的参数;id";至";doc";。有什么想法吗
我必须更改firestoreconnect函数,如下所示,
firestoreConnect((props) => [
{
collection: "questions",
doc: props.match.params.examId,
},
])
谢谢你们。。