Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bedrockstreaming/form-redux

Package Overview
Dependencies
Maintainers
8
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bedrockstreaming/form-redux

`form-redux` is a redux slice for managing the forms steps.

  • 0.9.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-96.97%
Maintainers
8
Weekly downloads
 
Created
Source

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.

FAQs

Package last updated on 16 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc