我目前正在将styled-componentsReact 中的库用于Form. 单击POST“创建”时,组件会发送请求。Button
import { Form, Button } from "react-bootstrap";
import React, { useState, useEffect } from "react";
import styled from "styled-components";
const StyledInput = styled(Form.Control)`
padding: 2px 5px;
width: 150px;
margin-right: 20px;
height: 50px;
`;
function Builder() {
const [name, setName] = useState("");
return (
<GridWrapper>
<h1>Builder</h1>
<Form>
<Form.Row>
<Form.Group controlId="name" bssize="large">
<Form.Label>Probet Name</Form.Label>
<StyledInput
size="sm"
required
value={name}
type="String"
onChange={(e) => setName(e.target.value)}
className="smaller-input"
/>
</Form.Group>
</Form.Row>
</Form>
<Button type="submit" onClick={handleSubmit}>
Create
</Button>
</GridWrapper>
);
}
My question is, I have passed the `required` prop into the `StyledInput` component, yet when I click on the "Create" `Button` it still sends through an empty String. Is there a quick way to validate this using `styled-components` or do I have to write something myself in the `handleSubmit` function?
慕莱坞森
冉冉说
随时随地看视频慕课网APP
相关分类