Local主机上的空白白屏:我的React项目中的3000
我的 React 项目中的 localhost:3000 出现空白屏幕。组件不会被渲染。我猜问题出在一个组件上,因为当我从 JSX 中注释掉该组件(SearchForm.js)时,其他组件确实出现了。请强调可能导致该问题的原因。感谢
SearchForm.js
import { Form, Col } from 'react-bootstrap'
export default function SearchForm({ params, onParamChange }) {
return (
<Form className="mb-4">
<Form.Row className="align-items-end">
<Form.Group as={Col}>
<Form.Label>Description</Form.Label>
<Form.Control onChange={onParamChange} value={params.description} name="description" type="text" />
</Form.Group>
<Form.Group as={Col}>
<Form.Label>Location</Form.Label>
<Form.Control onChange={onParamChange} value={params.location} name="location" type="text" />
</Form.Group>
<Form.Group as={Col} xs="auto" className="ml-2">
<Form.Check onChange={onParamChange} value={params.full_time} name="full_time" id="full-time" label="Only Full Time" type="checkbox" className="mb-2" />
</Form.Group>
</Form.Row>
</Form>
)
}
App.js
import React, { useState } from 'react';
import useFetchJobs from './useFetchJobs'
import { Container } from 'react-bootstrap'
import Job from './Job'
import JobsPagination from './JobsPagination';
import SearchForm from './SearchForm';
function App() {
const [params, setParams] = useState({})
const [page, setPage] = useState(1)
const { jobs, loading, error, hasNextPage } = useFetchJobs(params, page)
function handleParamChange(e) {
const param = e.target.name
const value = e.target.value
setPage(1)
setParams(prevParams => {
return { ...prevParams, [param]: value }
})
}
return (
<Container className="my-4">
<h1 className="mb-4">GitHub Jobs</h1>
<SearchForm params={params} onParamChange={handleParamChange} />
<JobsPagination page={page} setPage={setPage} hasNextPage={hasNextPage} />
{loading && <h1>Loading...</h1>}
{error && <h1>Error. Try Refreshing.</h1>}
{jobs.map(job => {
return <Job key={job.id} job={job} />
})}
<JobsPagination page={page} setPage={setPage} hasNextPage={hasNextPage} />
</Container>
)
}
export default App;
I am getting blank white screen on localhost:3000 in my React project. The components dont get rendered. I guess the issue is with one component, because when i comment out that component(SearchForm.js) from JSX, the other components do show up. Kindly highlight what could be the possiblities causing the issue. Thanks
SearchForm.js
import { Form, Col } from 'react-bootstrap'
export default function SearchForm({ params, onParamChange }) {
return (
<Form className="mb-4">
<Form.Row className="align-items-end">
<Form.Group as={Col}>
<Form.Label>Description</Form.Label>
<Form.Control onChange={onParamChange} value={params.description} name="description" type="text" />
</Form.Group>
<Form.Group as={Col}>
<Form.Label>Location</Form.Label>
<Form.Control onChange={onParamChange} value={params.location} name="location" type="text" />
</Form.Group>
<Form.Group as={Col} xs="auto" className="ml-2">
<Form.Check onChange={onParamChange} value={params.full_time} name="full_time" id="full-time" label="Only Full Time" type="checkbox" className="mb-2" />
</Form.Group>
</Form.Row>
</Form>
)
}
App.js
import React, { useState } from 'react';
import useFetchJobs from './useFetchJobs'
import { Container } from 'react-bootstrap'
import Job from './Job'
import JobsPagination from './JobsPagination';
import SearchForm from './SearchForm';
function App() {
const [params, setParams] = useState({})
const [page, setPage] = useState(1)
const { jobs, loading, error, hasNextPage } = useFetchJobs(params, page)
function handleParamChange(e) {
const param = e.target.name
const value = e.target.value
setPage(1)
setParams(prevParams => {
return { ...prevParams, [param]: value }
})
}
return (
<Container className="my-4">
<h1 className="mb-4">GitHub Jobs</h1>
<SearchForm params={params} onParamChange={handleParamChange} />
<JobsPagination page={page} setPage={setPage} hasNextPage={hasNextPage} />
{loading && <h1>Loading...</h1>}
{error && <h1>Error. Try Refreshing.</h1>}
{jobs.map(job => {
return <Job key={job.id} job={job} />
})}
<JobsPagination page={page} setPage={setPage} hasNextPage={hasNextPage} />
</Container>
)
}
export default App;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这看起来不错,需要更多信息,比如您如何在另一个文件中导入和使用它。
This seems okay, will need more information, Like how did you import and use it in another file.
尝试出来后,我决定直接从React-Bootstrap导入{ROW}。
但是,如果您想继续进行表单。行程,尝试检查如何在index.js中导入引导方式
After trying it out, I decided to just import { Row } directly from react-bootstrap.
But if you would like to continue with Form.Row, try checking how you imported bootstrap in index.js