0.9.1 • Published 4 months ago
@bedrockstreaming/form-redux v0.9.1
form-redux
form-redux
is a redux slice for managing the forms steps.
:question: Why
Since we are using react-hook-form
to persist data locally, we are only storing the form data and step information on each form submission.
:building_construction: Install
npm install @bedrockstreaming/form-redux
:rocket: Usage
Import and subscribe the reducer.
// reducers
import { reducer as forms } from '@bedrockstreaming/forms';
combineReducers({ forms, ... });
Use redux to control the form state.
// a form using actions
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { FormBuilder } from '@bedrockstreaming/form-builder';
import {
getCurrentStepIndex,
isLastStep,
resetForm,
initForm,
setNextStep,
} from '@bedrockstreaming/form-redux';
import { schema, formId } from './path/to/my/config';
import { fooSubmitAction } from '<my-app-module>';
export const FooForm = () => {
const dispatch = useDispatch();
const currentStepIndex = useSelector(getCurrentStepIndex(formId));
const shouldSubmit = useSelector(isLastStep(formId));
useEffect(() => {
dispatch(initForm(formId, schema));
}, [dispatch]);
const handleSubmit = (fieldValues) => {
if (shouldSubmit) {
dispatch(fooSubmitAction(fieldValues));
dispatch(resetForm(formId));
} else {
dispatch(setNextStep(formId));
}
};
return (
<FormBuilder
dictionary={dictionary}
schema={schema}
onSubmit={handleSubmit}
currentStepIndex={currentStepIndex}
/>
);
};
Running unit tests
Run nx test form-redux
to execute the unit tests via Jest.
0.9.1-fix-required.0
4 months ago
0.9.1
4 months ago
0.9.0
5 months ago
0.8.5-add-meta-display-required-hint.0
5 months ago
0.8.5-bump-nx.0
1 year ago
0.8.4
2 years ago
0.8.4-testprerelease.1
2 years ago
0.8.4-testprerelease.0
2 years ago
0.8.5-update-nx-13.0
2 years ago
0.8.3
2 years ago
0.8.2
2 years ago
0.8.1
2 years ago
0.8.0
2 years ago
0.7.1
2 years ago
0.7.0
2 years ago
0.6.1
2 years ago
0.6.0
2 years ago
0.5.1
2 years ago
0.5.0
2 years ago
0.4.1
2 years ago
0.4.0
2 years ago
0.3.0
2 years ago
0.2.1
2 years ago
0.2.0
2 years ago
0.1.0
2 years ago
0.0.1
2 years ago