# Shared strings

Shared strings let you store repeated text in a central Map and reference it by key from each cell. This reduces duplicated text in `sheetData` and keeps imports/exports consistent with Excel-style shared strings.

When shared strings are enabled, a cell can store an `ss` key and the actual text lives in `sharedStrings`. If `ss` is present, it takes precedence over any string or formatted value on the cell.

```tsx
// Before shared strings
{
  ue: { sv: "Hello" },
  fv: "Hello",
}

// With shared strings (Map-based)
{
  ss: "0"
}
// sharedStrings.get("0") === "Hello"
```

### Usage

```tsx
const App = () => {
  const [sharedStrings, onChangeSharedStrings] = useState<Map<string, string>>(
    new Map(),
  );

  const {
    getFormattedValue,
    getEffectiveExtendedValue,
    getUserEnteredExtendedValue,
  } = useSpreadsheetState({
    sharedStrings,
    onChangeSharedStrings,
  });

  // YJS automatically uses Map-based shared strings
  useYSpreadsheetV2({
    onChangeSharedStrings,
  });

  // For search, so it looks for shared strings index
  useSearch({
    getFormattedValue,
  });

  return (
    <CanvasGrid
      getFormattedValue={getFormattedValue}
      getUserEnteredExtendedValue={getUserEnteredExtendedValue}
      getEffectiveExtendedValue={getEffectiveExtendedValue}
    />
  );
};
```

### Import and export

* Excel/ODS/CSV imports honor `enabledSharedStrings`.
* Exports use `sharedStrings` when `ss` is present (shared strings take precedence over cell-level string/format values).

### Notes

* Shared string entries are not garbage-collected on delete, similar to Excel. Cells simply stop referencing their keys.
