Postingan lainnya
Kelas Premium!
Belajar Javascript untuk website
Gunakan kupon "mulaijs" untuk diskon 75 ribu!
error tentang "Error: React.Children.only expected to receive a single React element child."
saya mau mengintegrasikan API pada page DetailPage,namun pada saat menghubungkan dengan APInya muncul error Error: React.Children.only expected to receive a single React element child. . Saya sudah mencari letak salahnya,namun masih belum ketemu dimana.
errornyaini kodenya
//page.js pada store/action/page.js
import axios from "axios";
import { FETCH_PAGE } from "../types";
export const fetchPage = (url, page) => (dispatch) => {
return axios.get(url).then((response) => {
dispatch({
type: FETCH_PAGE,
payload: {
[page]: response.data,
},
});
});
};
//file page.js pada store/reducers/page.js
import { FETCH_PAGE } from "../types";
const initialState = {};
export default function foo(state = initialState, action) {
switch (action.type) {
case FETCH_PAGE:
return {
...state,
...action.payload,
};
default:
return state;
}
}
//file detailpage.js pada folder src/pages.detailspage.js
import React, { Component } from "react";
import Fade from "react-reveal/Fade";
import { connect } from "react-redux";
import Header from "parts/Header";
import PageDetailTitle from "parts/PageDetailTitle";
import FeaturedImage from "parts/FeaturedImage";
import PagedetailsDescription from "parts/PageDetailsDescription";
import BookingForm from "parts/BookingForm";
import Categories from "parts/Categories";
import Testimony from "parts/Testimony";
import Footer from "parts/Footer";
import { checkoutBooking } from "store/actions/checkout";
import { fetchPage } from "store/actions/page";
class DetailsPage extends Component {
componentDidMount() {
window.title = "Details Page";
window.scrollTo(0, 0);
if (!this.props.page[this.props.match.params.id])
this.props.fetchPage(
`${process.env.REACT_APP_HOST}/api/v1/member/detail-page/${this.props.match.params.id}`,
this.props.match.params.id
);
}
render() {
const { page, match } = this.props;
const breadcrumb = [
{ pageTitle: "Home", pageHref: "" },
{ pageTitle: "House Details", pageHref: "" },
];
console.log(page);
if (!page[match.params.id]) return null;
return (
<>
<Header {...this.props} />
<PageDetailTitle breadcrumb={breadcrumb} data={page[match.params.id]} />
<FeaturedImage data={page[match.params.id].imageId} />
<section className="container">
<div className="row">
<div className="col-7 pr-5">
<Fade bottom>
<PagedetailsDescription data={page[match.params.id]} />
</Fade>
</div>
<div className="col-5">
<Fade bottom>
<BookingForm
itemDetails={page[match.params.id]}
startBooking={checkoutBooking}
/>
</Fade>
</div>
</div>
</section>
<Categories data={page[match.params.id].activityId} />
<Testimony data={page[match.params.id].testimonial} />
<Footer />
</>
);
}
}
const mapStateToProps = (state) => ({
page: state.page,
});
export default connect(mapStateToProps, { checkoutBooking, fetchPage })(
DetailsPage
);
0
1 Jawaban:
<div>Pastikan element root nya hanya ada satu,<br>coba gunakan React Fragment<br><br> <React.Fragment><br> </React.Fragment><br><br><a href="https://reactjs.org/docs/fragments.html">https://reactjs.org/docs/fragments.html</a></div>
1