Pat*_*kkx 7 javascript typescript definitelytyped reactjs redux-form
正在寻找多年,没有找到任何值得的东西.
当我使用flow时,我可以简单地说:
import { type FieldProps, FormProps } from 'redux-form';
Run Code Online (Sandbox Code Playgroud)
是否有类似(并且那么简单)的方法在typescript中正确设置道具到redux形式?
文档没有说什么关于打字稿,只有一个页面用于Flow打字.
但是,我发现我可以propTypes从redux-form 导入类似的东西:
import { reduxForm, propTypes } from 'redux-form'
Run Code Online (Sandbox Code Playgroud)
但是 - redux-form没有像propTypes导出的那样,所以docs有点不赞成.
链接:https://redux-form.com/7.2.1/docs/api/props.md/
提前感谢您提供任何帮助.
tl;dr class RegistrationForm extends React.PureComponent<any> {
what to drop here ^^^^^
Run Code Online (Sandbox Code Playgroud)
Ant*_*vik 11
您需要@types/redux-form使用软件包管理器安装软件包.该@types/redux-form包包括包的类型定义redux-form.
然后,您可以从中导入类型定义redux-form,例如InjectedFormProps.
你的表格reduxForm()应该包含延伸的道具InjectedFormProps<FormData = {}, P = {}>.
reduxForm() 类型是通用的 reduxForm<FormData = {}, P = {}>(...
看例子:
import * as React from 'react';
import { reduxForm, InjectedFormProps, Field } from 'redux-form';
import { IUser } from './index';
interface IProps {
message: string;
}
class UserForm extends React.Component<InjectedFormProps<IUser, IProps> & IProps> {
render() {
const { pristine, submitting, reset, handleSubmit, message } = this.props;
return (
<form onSubmit={handleSubmit}>
<div>{message}</div>
<div>
<label>First Name </label>
<Field
name="firstName"
component="input"
type="text"
placeholder="First Name"
/>
</div>
<div>
<label>Last Name </label>
<Field
name="lastName"
component="input"
type="text"
placeholder="Last Name"
/>
</div>
<div>
<button type="submit" disabled={pristine || submitting}>
Submit
</button>
<button type="button" disabled={pristine || submitting} onClick={reset}>
Clear Values
</button>
</div>
</form>
);
}
}
export default reduxForm<IUser, IProps>({
form: 'userForm',
})(UserForm);
Run Code Online (Sandbox Code Playgroud)
@types/redux-form包的源代码位于此处.你可以在redux-form-tests.tsx文件中看到那里的类型和更复杂的例子,用于类型检查.
| 归档时间: |
|
| 查看次数: |
4912 次 |
| 最近记录: |