Type Definitions
object
# UseRecordOptions
Example of restricting useRecord to operate only on a finite set of properties:
const { record, handleChange, submit } = useRecord(initialRecord, resource.id, {
includeParams: ['name', 'surname', 'school.name'],
})
// handleChange('otherProperty', 'value') wont affect the `record`
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
includeParams |
Array.<string>
|
<optional> |
If set, useRecord will operate only on selected params. The rules here will be applied to, both initialRecord params and all the params set by handleChange. It wont be applied to params, set in submit |
object
# UseRecordResult
Properties:
Name | Type | Description |
---|---|---|
record |
RecordJSON
|
recordJSON instance for given resource. |
handleChange |
OnPropertyChange
|
Function compatible with onChange method supported by all the components wrapped by, BasePropertyComponent. |
submit |
UseRecordSubmitFunction
|
Triggers submission of the record. Returns a promise. |
loading |
boolean
|
Flag indicates loading. |
progress |
number
|
Upload progress |
setRecord |
React.Dispatch.<React.SetStateAction.<RecordJSON>>
|
Sets value for the record from the outside. You might use it when you update the record, simultaneously in an another place. |
isSynced |
boolean
|
Indicates if record is in "synced" state. It is when it was either just created from initial, record or submitted. After at least one handleChange it is false until the successful submit |
# UseRecordSubmitFunction(customParamsopt, optionsopt)
execution function updates its inner state with the returned by the backend record. This might
not be the need in your case, so you can turn it of by setting updateOnSave
to false.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options.updateOnSave |
boolean
|
<optional> |
Indicates if record should be updated after the submit action, which returns updated record. You might turn this of if you use function like lodash debounce, where you might have old state in the action response. |
customParams |
Record.<string, string>
|
<optional> |
Any additional parameters you want to be merged to the payload. |
options |
object
|
<optional> |
Custom options passed to submit function |