Skip to content

Commit 9e1a3dd

Browse files
committed
[website] update get-started
1 parent 7da845d commit 9e1a3dd

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

docs/get-started.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,32 @@ import 'react-base-table/styles.css'
2727
...
2828
```
2929

30-
**Make sure each item in `data` is unique by a key, the default key is `id`, you can customize it via `rowKey`**
30+
### unique key
3131

32-
**`width` and `height` are required to display the table properly**
32+
`key` is required for column definition or the column will be ignored
33+
34+
Make sure each item in `data` is unique by a key, the default key is `id`, you can customize it via `rowKey`
35+
36+
### size
37+
38+
`width` is required for column definition, but in flex mode(`fixed={false}`), you can set `width={0}` and `flexGrow={1}` to achieve flexible column width, checkout the [Flex Column](https://autodesk.github.io/react-base-table/examples/flex-column) example
39+
40+
`width` and `height`(or `maxHeight`) are required to display the table properly
3341

3442
In the [examples](https://autodesk.github.io/react-base-table/examples)
3543
we are using a wrapper `const Table = props => <BaseTable width={700} height={400} {...props} />` to do that
3644

37-
If you want it responsive, you can use the [`AutoResizer`](https://autodesk.github.io/react-base-table/api/autoresizer) to make the table fill the container, checkout the [Auto Resize example](https://autodesk.github.io/react-base-table/examples/auto-resize)
45+
If you want it responsive, you can use the [`AutoResizer`](https://autodesk.github.io/react-base-table/api/autoresizer) to make the table fill the container, checkout the [Auto Resize](https://autodesk.github.io/react-base-table/examples/auto-resize) example
46+
47+
### closure problem in custom renderers
48+
49+
In practice we tend to write inline functions for custom renderers, which would make `shouldUpdateComponent` always true as the inline function will create a new instance on every re-render, to avoid "unnecessary" re-renders, **`BaseTable` ignores functions when comparing column definition by default**, it works well in most cases before, but if we use external data instead of reference state in custom renderers, we always get the staled initial value although the data has changed
50+
51+
It's recommended to inject the external data in column definition to solve the problem, like `<Column foo={foo} bar={bar} cellRenderer={({ column: { foo, bar }}) => { ... } } />`, the column definition will update on external data change, with this pattern we can easily move the custom renderers out of column definition for sharing, the downside is it would bloat the column definition and bug prone
52+
53+
Things getting worse with the introduction of React hooks, we use primitive state instead of `this.state`, so it's easy to encounter the closure problem, but with React hooks, we can easily memoize functions via `useCallback` or `useMemo`, so the implicit optimization could be replaced with user land optimization which is more intuitive, to turn off the implicit optimization, set `ignoreFunctionInColumnCompare` to `false` which is introduced since `v1.11.0`
54+
55+
Here is an [example](https://autodesk.github.io/react-base-table/playground#MYewdgzgLgBKA2BXAtpGBeGBzApmHATgIZQ4DCISqEAFAIwAMAlAFCiSwAmJRG2ehEjgAiPGghSQANDABMDZixY4AHgAcQBLjgBmRRPFg0mGAHwwA3ixhxw0GAG1QiMKQIyIOKBRduAunwASjhEwFAAdIieAMpQQjSKNuz2DgCWWGCaOABiLmGp4B5eAJIZWblg+eABmMGhEVE4sfFQBIg4rEl2sGlgAFY4YRRUYEVQxf2D3pSSNTB1YZExcaQ0evCenTAEXogEYDA01jYwADymxydnnKkAbjDQAJ7wOOgWFjBqRJw3YFgAXDAACwyG4QNTwIiPQEAch0LxUMJkfSiUFSOkeFFceCgsPBoRwAFoAEZeADuODwMJgAF8aRcrldTsTEFAoOAYOAyPBUsAANZvYxmB5eHzYgjiEC+QgwADUMDoTHpstOAHoWWzwAzGTZTpDSfBtTrdakwGpWZdjTYoI81K8AETAAAWgz5xJAKntlqtztdOE4b3SmR2FSqYBp3uNXKdRD+rwsOGFnnGZRDeTR4BoOHCcQIuAivv5-qVkauqqNxtKwcTOnTBQOptsI1syC+O1LZ1V+pwho7eqIBorOtOpvNUA7VxtdvQjpd-PdnonJ0LfP9gcmQxmqAjVqu0djuDeifQ5mTEwGm5GWZzRDzXnCK+LO935aX56mMFUrV43DiMHZTaSDAnC6KaqQZmAfZdgOPZDp2Ny3HBpwACoDi8MA6KkKj+sBPBvL+RA0jAQblHW4ATMMkgUK2t7xiRaaVBB9J9pRqBLhY4ScRI1AOAwfjPlaBEAOJeG4gomCetjSgQAnGs44rrhe0zNgA-FJ4owICLggZh+CcLJZZwbqrEHBxXFbpADh0PxMCvlapwmZYnEPhZEAOLINl2caDkWU55kjG5ADMnlGWcjlmS5AUOECIWRmqqHEi8FZqtqrARkAA) to demonstrate
3856

3957
## Browser Support
4058

@@ -45,8 +63,8 @@ If you want it responsive, you can use the [`AutoResizer`](https://autodesk.gith
4563
## Playground
4664

4765
```jsx live
48-
const columns = generateColumns(10)
49-
const data = generateData(columns, 200)
66+
const columns = generateColumns(10);
67+
const data = generateData(columns, 200);
5068

51-
export default () => <Table columns={columns} data={data} />
69+
export default () => <Table columns={columns} data={data} />;
5270
```

0 commit comments

Comments
 (0)