Gathering detailed insights and metrics for react-final-form-named-arrays
Gathering detailed insights and metrics for react-final-form-named-arrays
Gathering detailed insights and metrics for react-final-form-named-arrays
Gathering detailed insights and metrics for react-final-form-named-arrays
react-final-form-arrays
A component for rendering and editing arrays 🏁 React Final Form
final-form-arrays
Array Mutators for 🏁 Final Form
react-final-form
🏁 High performance subscription-based form state management for React
react-final-form-listeners
A collection of components to listen to 🏁 React Final Form fields
npm install react-final-form-named-arrays
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1 Stars
38 Commits
1 Watching
18 Branches
1 Contributors
Updated on 12 May 2023
JavaScript (97.46%)
TypeScript (2.54%)
Cumulative downloads
Total Downloads
Last day
-6.7%
14
Compared to previous day
Last week
-1.1%
88
Compared to previous week
Last month
-8%
355
Compared to previous month
Last year
-3.8%
4,562
Compared to previous year
1
4
64
Provides a component very similar to FieldArray, but that allows you to refer to items within the array by a unique key as well as by an index. This repo is for all intents and purposes a fork of react-final-form-arrays
. The only reason it is not an actual fork is so that I can keep a separate fork with which to continue contributing to react-final-form-arrays
.
This component was born out of a need to asynchronously update values within a Field Array, whilst the order of the array is subject to change. A callback that uses an index is obviously going to cause problems, and so some kind of unique identifier is required.
(The actual use case, was uploading multiple files at the same time. We want to update the progress of individual files, but calling fields.update(index, value)
would produce undesirable results if one upload was deleted whilst another was in progress - as the array indicies would all shift). We therefore need to be able to update by referring to some sort of unique key, rather than an index.
The basic idea is that each element in the array has a name (key), that can be used to refer to it's corresponding element. The FieldArray
component keeps track of the names in a NAME_LIST
stored in the fields meta data. Any changes made to the array are kept track of and applied to the NAME_LIST
.
npm install react-final-form-named-arrays
react-final-form-named-arrays
exports a component (FieldArray
), a hook (useFieldArray
), and an objects containing Mutators (see final-form docs). These three exports behave are very similar to the corresponding entities from react-final-form-arrays
however there are a few key differences:
FieldArray
and useFieldArray
accept an additional prop getItemName
(see below).getItemName
prop is absent, the behaviour will remain the same as a normal FieldArray
getItemName
is present:
remove
and update
mutators can optionally be called with a string, instead of an index.fields.map
returns an iterator with an additional argument (value) - further detail belowgetItemName?: (value: any, values: ?any[]) => string
Under the hood, FieldArray keeps track of an array of keys (or names) for all of the items in your array. Every time the array is rearranged in some way, the array of names is also updated. The allows you to call functions like update
or remove
with a key rather than an index. getItemName
is the function used to assign a name to each item in your list. It is run only once for each item - either when the form is (re)initialised or when the item is added to the array. It is called with the following arguments:
value
: is the item that is being added to the array
values
: is the value of the whole array. When items are being added to an array, the name is generated before it is added, so values will refer to the array before that item is added. When the array of names is seeded from initialValues
values will be equal to initialValues
getItemName
must return a string. It is important that the item 'name' be unique, and should be determined in such a way that
// NEED TO ADD SOMETHING ABOUT USING MUTATORS WHEN NOT CURRIED VIA FIELDS E.G. USING THEM FROM 'FORM'
// Need to add some warnings about using changeValue
I am going to test-drive 'named-fields' as it is for a little while and see how well things work before taking it any further. There are a few changes I'm considering, but think it best just to try it out for a bit first.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/12 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
102 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More