Class

useRecord

useRecord

Type Definitions

object

# UseRecordOptions

Custom options passed to useRecord as the third argument.

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

View Source adminjs/src/frontend/hooks/use-record/use-record.type.ts, line 8

object

# UseRecordResult

Result of useRecord hook
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

View Source adminjs/src/frontend/hooks/use-record/use-record.type.ts, line 44

# UseRecordSubmitFunction(customParamsopt, optionsopt)

Submit function which either creates a record or updates it. By default, after successful

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

View Source adminjs/src/frontend/hooks/use-record/use-record.type.ts, line 28