Typing redux forms v7 with TypeScript and React

后端 未结 5 2076
野性不改
野性不改 2020-12-29 15:29

I\'ve got a plain react-redux-powered form. I wish for there to be a form.container.tsx and a form.component.tsx, where form.container.tsx holds all the connections to redux

5条回答
  •  孤独总比滥情好
    2020-12-29 16:06

    I also ran into this issue trying to initialise my form from redux state, as per the example in https://redux-form.com/7.0.4/examples/initializefromstate/

    I ended up getting around it by connecting the component at a higher level, eg:

    component.tsx:

    interface DummyFormComponentProps {} extends InjectedFormProps
    
    const DummyFormComponent: React.SFC = props => {
      return (
        
    // Fields go here
    ) } export const DummyForm = reduxForm({ form: "dummy-form" })(DummyFormComponent) // Trying to connect here also gave errors with DecoratedComponentClass

    container.tsx:

    interface DummyFormContainerProps {} extends Pick
    
    const submitForm = (formValues: object) => {
      alert(formValues);
    };
    
    const DummyFormContainer: React.SFC = props => {  
      return (
        
      )
    }
    
    const mapStateToProps = (state: State) => ({
      initialValues: {}
    });
    const mapDispatchToProps = (dispatch: object) => {
      return {};
    };
    export default connect(mapStateToProps, mapDispatchToProps)(DummyFormContainer)
    

提交回复
热议问题