# RSC Mode Server Actions

The [RSC](https://react.dev/blog/2023/03/22/react-labs-what-we-have-been-working-on-march-2023#react-server-components) architecture introduces [`server actions`](https://react.dev/reference/react/use-server), which are seamlessly integrated in the server mode of the KendoReact Grid.

Server-actions compatibility allows passing functions to the component's callbacks, such as `onDataStateChange` or `onItemChange`, enabling the execution of custom server-side logic.

## Available Server Actions

In the server mode of the Grid, the events fall into two categories:

1. Data state change related events:
   * [`onFilterChange`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops#onfilterchange)
   * [`onSortChange`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops#onsortchange)
   * [`onPageChange`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops#onpagechange)
   * [`onGroupChange`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops#ongroupchange)
   * [`onDataStateChange`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops#ondatastatechange)—triggered when either one of the `onFilterChange`, `onSortChange`, `onPageChange` or `onGroupChange` events occurs.
2. Grid state operation related events:
   * [`onSelectionChange`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops#onselectionchange)
   * [`OnGroupExpandChange`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops)
   * [`OnDetailExpandChange`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops)
   * [`OnEditChange`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops)

## Server Actions Configuration

To use event handlers on a server page, you can use the same setup as you would for a Grid on a client page. The key differences are:

* Event handlers must be marked as `async` and include `'use server'` at the top.
* Non-serializable event arguments should be wrapped inside a `ServerEvent<T>` type to ensure compatibility.

> Client event arguments such as `nativeEvent`, `syntheticEvent`, `target`, `targetEvent`, and `focusElement` cannot be serialized to the server and will always be `undefined`.

Here is an example of a server action managing the Grid’s data state:

```tsx
const onDataStateChange = async (event: ServerEvent<GridDataStateChangeEvent>) => {
    'use server';

    cookies().set(TAG, JSON.stringify(event.dataState)); //save state
};

return <Grid onDataStateChange={onDataStateChange} dataItemKey={dataItemKey}></Grid>;
```

The following example demonstrates how to wire a server action to the `onDataStateChange` event to persist sorting, filtering, paging, and grouping state in cookies across page reloads.

[Demo Source](https://demos.telerik.com/kendo-react-ui/grid/server-components/server-actions/source.txt)

## Limitations

### Client-only Events

There are some current events of the Grid that only make sense in a client scenario. As a result, the following events will not be triggered when the Grid is used as a server component:

* [`onScroll`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops),
* [`onKeyDown`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops),
* [`onContextmenu`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops),
* [`onNavigationAction`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops),
* [`onClipboard`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops)
* [`OnColumnResize`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops)

## Suggested Links

* [КendoReact Grid RSC Mode Overview](https://www.telerik.com/kendo-react-ui/components/grid/rsc-mode)
* [Getting Started with КendoReact Grid RSC Mode](https://www.telerik.com/kendo-react-ui/components/grid/getting-started/get-started-rsc)
