# Immer

请参见下面的一个例子:

```javascript
import produce from 'immer';

export default {

  // state is the array of cell IDs for this page
  state: [ '1' ],

  reducers: {

    reorder: produce((state, { fromIndex, toIndex }) => {
      const [ id ] = state.splice(fromIndex, 1);
      if (id) {
        state.splice(toIndex, 0, id);
      }
    }),

    'cells/create': produce((state, { id, atIndex }) => {
      if (atIndex > state.length) {
        throw new Error('Cell index too high');
      }

      state.splice(atIndex, 0, id);
    }),

    'cells/delete': produce((state, { atIndex }) => {
      state.splice(atIndex, 1);
    }),

  },

};
```

如果你想用Immer produce包装所有reducer，请检查[Rematch Immer插件](https://github.com/rematch/rematch/tree/master/plugins/immer)。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rematch.gitbook.io/handbook/ji-qiao/immer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
