marmelab / react-admin

A frontend Framework for single-page applications on top of REST/GraphQL APIs, using TypeScript, React and Material Design
http://marmelab.com/react-admin
MIT License
24.77k stars 5.22k forks source link

Export useSimpleFormIterator context hook for use in custom buttons #7508

Closed nselikoff closed 2 years ago

nselikoff commented 2 years ago

Is your feature request related to a problem? Please describe. As described in ArrayInput usage, custom buttons can be passed in for add, remove and reorder. However, in trying to implement a custom add button, it seems the useSimpleFormIterator hook is not exported from the ra-ui-materialui package. Having this hook available seems necessary to make custom buttons work, unless I'm missing something.

import React from "react";
import AddIcon from "@material-ui/icons/AddCircleOutline";
import { Button, useSimpleFormIterator } from "react-admin";

export const CustomAddButton = (props) => {
  const { add } = useSimpleFormIterator();
  return (
    <Button label="ra.action.add" {...props} onClick={() => add()}>
      <AddIcon />
    </Button>
  );
};

The actual error when attempting to import the hook is: export 'useSimpleFormIterator' (imported as 'useSimpleFormIterator') was not found in 'react-admin'

react-admin 3.19.10 ra-ui-materialui 3.19.10

Describe the solution you'd like Add additional exports to ArrayInput - at least useSimpleFormIterator

nselikoff commented 2 years ago

I should add some more context: I'm trying to find the right place to add an item to an ArrayInput programmatically, i.e. with values determined from an interaction that happens before the new item is added to the array. So I'm trying to get access to the add mutator so I can pass in pre-filled values for that new item.