question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ArrayInput breaks when value is null

See original GitHub issue

I’m not sure this is a bug or if this was intended with 4.x version of react-admin.

What you were expecting: ArrayInputs render when field value is null.

What happened instead: A cannot read properties of null (reading 'map') error is thrown here in react-hook-form: https://github.com/react-hook-form/react-hook-form/blob/v7.27.0/src/useFieldArray.ts#L103. It appears unless a field value is undefined react-hook-form will not default to an empty array. Based on line 101 unless a field value is undefined react-hook-form will not default to an empty array.

Steps to reproduce: Set any field value in the v4 sandbox test data.tsx file intended to be rendered with ArrayInput to null (ie: ‘backlinks’).

You can see the error here in this sandbox when you navigate to the edit view for post with id 1. https://codesandbox.io/s/boring-benz-5odpst

Environment

  • React-admin version: 4.1.0
  • React version: 1.17.0
  • Browser: Chrome 101.0.4951.64 (Official Build) (x86_64)
  • Stack trace (in case of a JS error):

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
slax57commented, Aug 8, 2022

According to me this should be fixed on react-hook-form’s side (the ‘map’ error actually comes from their code). That’s what I tried to argue here https://github.com/react-hook-form/react-hook-form/issues/4826#issuecomment-1208145917 .

I don’t see how we could fix this in RA, since we do not know upfront if a given field will be used inside an ArrayInput or not.

Best we could do is mention in the docs that the value cannot be null if it is to be used with an ArrayInput.

1reaction
slax57commented, May 31, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to know if input array elements are empty? - Stack Overflow
$imply use array filter which will remove any empty or falsey items from the array, then check if anything is left:
Read more >
filter_input_array - Manual - PHP
An array value will be false if the filter fails, or null if the variable is not set. ... case INPUT_GET : $loopThrough...
Read more >
Input Components - React-admin - Marmelab
This input does not handle null values. You would need the <NullableBooleanInput /> component if you have to handle non-set booleans.
Read more >
Null-Terminated Character Arrays - Programming C++
The result is what I like to call a “null-terminated character array”, ... It is the first character in the ASCII character table,...
Read more >
useFieldArray - Simple React forms validation
The input value will be registered during this action. ... (and not index ) must be added as the component key to prevent...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found