3.2.12 • Published 3 years ago

@saeon/quick-form v3.2.12

Weekly downloads
16
License
MIT
Repository
github
Last release
3 years ago

@saeon/quick-form

Quickly add localised state to your component tree - there are many form-helper libraries in the world. Many of them try to draw components, which makes these libraries larger than necessary, limited in terms of what they include, and generally unnecessary considering how easy React makes it to manage state.

Usage

First install it

npm i @saeon/quick-form

Then include it in your project

import Q from '@saeon/quick-form'

And then use it

const Component = props => (
  <MyForm>
    <Q value1={false} value2={true}>
      {(updateForm, { value1, value2 }) => (
        <div>
          {/* Input 1 */}
          <button onClick={() => updateForm({ value1: !value1 })}>{value1}</button>
          {/* Input 2 */}
          <button onClick={() => updateForm({ value2: !value2 })}>{value2}</button>
        </div>
      )}
    </Q>
  </MyForm>
)

The Q component will re-render every time a form attribute's value changes. You can specify effects to run when this happens:

<Q
 value={false}
 effects={[
   (fields) => alert('Effect 1'),
   (fields) => alert('Effect 2'),
   ... etc.
 ]}
>
  {(updateForm, { ...fields }) => (
    <div onClick={() => updateForm({value: !value})}>{fields.value}</div>
  )}
</Q>
)

It's especially useful to use in a 'nested' fashion for maintaining performance of controlled inputs in large forms

const debounce = (cb, duration = 0) => {
  let timer
  return (...args) => {
    clearTimeout(timer)
    timer = setTimeout(() => {
      cb(...args)
    }, duration)
  }
}

const Form = () => (
  <Q val1 val2 val3 val4 etc>
    {(update, fields) => {
      return (
        <div>
          {/* val1  */}
          <Q
            effects={[
              /**
               * Debounce the update
               * to the main form
               */
              debounce(({ value }) => {
                if (fields.val1 !== value) {
                  update({ val1: value })
                }
              }, 500),
            ]}
            value={fields.val1}
          >
            {(update, { value }) => (
              /**
               * Debouncing the onChange handler
               * doesn't work so well
               */
              <input onChange={e => update({ value: e.target.value })} value={value} />
            )}
          </Q>

          {/* val2 */}
          <Q>...</Q>

          {/* val2 */}
          <Q>...</Q>

          {/* val99 */}
          <Q>...</Q>
        </div>
      )
    }}
  </Q>
)
abbrevacornacorn-jsxagent-baseagentkeepaliveaggregate-errorajvansi-alignansi-regexansi-stylesaprobaare-we-there-yetargparsearray-includesarray-unionarray.prototype.flatmapbabel-plugin-dynamic-import-nodebabel-plugin-polyfill-corejs2babel-plugin-polyfill-corejs3babel-plugin-polyfill-regeneratorbalanced-matchboxenbrace-expansionbracesbrowserslistbuffer-frombuiltinscacheable-requestcacachecall-bindcamelcasecallsitescaniuse-litechalkchownrci-infocintclean-stackcli-tablecli-boxesclone-responsecolor-convertcolor-nameconcat-mapconfigstorecommanderconsole-control-stringscore-js-compatconvert-source-mapcrypto-random-stringcross-spawndebugdeep-extenddecompress-responsecolor-supportdeep-isdefer-to-connectdefine-propertiesdelegatesdoctrinedir-globdepdduplexer3dot-propelectron-to-chromiumemoji-regexencodingend-of-streamenv-pathserr-codees-abstractes-to-primitiveescaladeescape-goatescape-string-regexpeslint-rule-composereslint-scopeeslint-utilsespreeeslint-visitor-keysesrecurseestraverseesqueryestree-walkeresutilsfast-deep-equalfast-globfast-json-stable-stringifyfast-levenshteinfast-memoizefiggy-puddingfastqfile-entry-cachefill-rangefind-upflat-cacheflattedfp-and-orfs.realpathfs-minipassfunctional-red-black-treegaugefunction-bindgensyncget-intrinsiccolorsget-stdinget-symbol-descriptionglobal-dirsget-streamglobalsglobbygotgraceful-fshashas-bigintshas-flagglob-parenthas-symbolshas-tostringtaghas-yarnhosted-git-infohttp-cache-semanticshttp-proxy-agenthas-unicodehumanize-mshttps-proxy-agentignore-walkignoreiconv-liteimport-lazyimurmurhashimport-freshindent-stringinfer-ownerinflightinheritsiniinternal-slotipis-bigintis-boolean-objectis-callableis-core-moduleis-ciis-date-objectis-globis-extglobis-fullwidth-code-pointis-installed-globallyis-lambdais-negative-zerois-npmis-numberis-number-objectis-objis-path-insideis-regexis-shared-array-bufferis-symbolis-typedarrayis-stringis-yarn-globalisexeis-weakrefjjujs-tokensjs-yamljsescjson-parse-even-better-errorsjson-parse-helpfulerrorjson-schema-traversejson-stable-stringify-without-jsonifyjson5jsonlinesjsonparseglobkeyvlatest-versionjsx-ast-utilskleurlevnlocate-pathlodashlodash.debouncelibnpmconfigloose-envifymake-dirlodash.mergelowercase-keyslru-cachemicromatchmake-fetch-happenmimic-responsemerge2minimatchminimistminipassminipass-fetchminipass-flushminipass-collectminipass-pipelineminipass-json-streamminipass-sizedminizlibmkdirpmsnatural-comparenegotiatornode-gypjson-buffernode-releasesnoptnormalize-urlnpm-bundlednormalize-package-datanpm-install-checksnpm-normalize-package-binnpm-package-argnpm-packlistnpm-pick-manifestnpm-registry-fetchnpmlogobject-assignobject-inspectobject-keysobject.assignobject.hasownobject.entriesobject.fromentriesobject.valuesonceoptionatorp-cancelablep-limitp-trypacoteparse-github-urlparent-modulepackage-jsonpath-existspath-is-absolutepath-keypath-parsepath-typepicomatchpicocolorsprepend-httpprelude-lsproc-logp-locatepromise-inflightprogresspromise-retryprop-typespunycodepumppupaqueue-microtaskrcp-maprc-config-loaderread-package-jsonreadable-streamreact-isread-package-json-fastregenerate-unicode-propertiesregenerateregenerator-runtimeregenerator-transformregexp.prototype.flagsregexppregexpu-coreregistry-urlregistry-auth-tokenregjsgenregjsparserrequire-from-stringremote-git-tagsresolveresponselikeresolve-fromretryrun-parallelreusifysafe-buffersemversafer-buffersemver-diffsemver-utilsset-blockingshebang-regexshebang-commandside-channelsignal-exitsisteransislashsmart-buffersockssocks-proxy-agentsource-mapsource-map-supportspawn-pleasespdx-correctspdx-exceptionsspdx-expression-parsessrispdx-license-idsstring.prototype.matchallstring-widthstring.prototype.trimstartstring.prototype.trimendstring_decoderstrip-ansistrip-json-commentssupports-colorsupports-preserve-symlinks-flagto-fast-propertiestartext-tableto-readable-streamtype-checktype-festto-regex-rangetypedarray-to-bufferunbox-primitiveunicode-canonical-property-names-ecmascriptunicode-match-property-ecmascriptunicode-match-property-value-ecmascriptunicode-property-aliases-ecmascriptunique-slugunique-filenameupdate-notifieruri-jsunique-stringurl-parse-laxutil-deprecatevalidate-npm-package-licensevalidate-npm-package-namewhichv8-compile-cachewide-alignwidest-lineword-wrapwrap-ansiwrappypromptsxdg-basediryamlyocto-queueyallistwrite-file-atomicwhich-boxed-primitive
3.2.9

3 years ago

3.2.8

3 years ago

3.2.12

3 years ago

3.2.11

3 years ago

3.2.10

3 years ago

3.2.7

3 years ago

3.2.6

3 years ago

3.2.5

3 years ago

3.2.4

3 years ago

3.2.3

3 years ago

3.2.2

3 years ago

3.1.9

3 years ago

3.2.1

3 years ago

3.2.0

3 years ago

3.1.8

4 years ago

3.1.7

4 years ago

3.1.6

4 years ago

3.1.5

4 years ago

3.1.3

4 years ago

3.1.2

4 years ago

3.1.1

4 years ago

3.0.3

4 years ago

3.1.0

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

2.0.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.1

4 years ago