( resource: Resource, propertyURL: string, opts?: useValueOptions, )
| 375 | * to empty array) and a callback for validation errors. See {@link useValue} |
| 376 | */ |
| 377 | export function useArray( |
| 378 | resource: Resource, |
| 379 | propertyURL: string, |
| 380 | opts?: useValueOptions, |
| 381 | ): [string[] | null, setValue] { |
| 382 | const [value, set] = useValue(resource, propertyURL, opts); |
| 383 | if (value == null) { |
| 384 | return [[], set]; |
| 385 | } |
| 386 | // If .toArray() errors, return an empty array. Useful in forms when datatypes haves changed! |
| 387 | // https://github.com/joepio/atomic-data-browser/issues/85 |
| 388 | let arr = []; |
| 389 | try { |
| 390 | arr = valToArray(value); |
| 391 | } catch (e) { |
| 392 | console.log(e, value, propertyURL, resource.getSubject()); |
| 393 | } |
| 394 | return [arr, set]; |
| 395 | } |
| 396 | |
| 397 | /** See {@link useValue} */ |
| 398 | export function useNumber( |
no test coverage detected