Skip to content

Commit 744c9bd

Browse files
committed
Merge branch 'ImedAdel-master'
2 parents 81d926d + eb36e75 commit 744c9bd

File tree

1 file changed

+10
-16
lines changed
  • frameworks/keyed/react-zustand/src

1 file changed

+10
-16
lines changed

frameworks/keyed/react-zustand/src/main.jsx

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,35 +120,29 @@ const getSelect = (state) => state.select
120120
const getRemove = (state) => state.remove
121121

122122
const Row = memo(
123-
({ itemId }) => {
123+
({ item }) => {
124124
const select = useStore(getSelect)
125125
const remove = useStore(getRemove)
126-
const itemLabel = useStore(
127-
useCallback(
128-
(state) => state.data.find((item) => item.id === itemId).label,
129-
[itemId]
130-
)
131-
)
132126
const isSelected = useStore(
133-
useCallback((state) => state.selected === itemId, [itemId])
127+
useCallback((state) => state.selected === item.id, [item.id])
134128
)
135129

136130
return (
137131
<tr className={isSelected ? "danger" : ""}>
138-
<td className="col-md-1">{itemId}</td>
132+
<td className="col-md-1">{item.id}</td>
139133
<td className="col-md-4">
140-
<a onClick={() => select(itemId)}>{itemLabel}</a>
134+
<a onClick={() => select(item.id)}>{item.label}</a>
141135
</td>
142136
<td className="col-md-1">
143-
<a onClick={() => remove(itemId)}>
137+
<a onClick={() => remove(item.id)}>
144138
<span className="glyphicon glyphicon-remove" aria-hidden="true" />
145139
</a>
146140
</td>
147141
<td className="col-md-6" />
148142
</tr>
149143
)
150144
},
151-
(prevProps, nextProps) => prevProps.itemId === nextProps.itemId
145+
(prevProps, nextProps) => prevProps.item === nextProps.item
152146
)
153147

154148
const Button = ({ id, cb, title }) => (
@@ -211,21 +205,21 @@ const Jumbotron = memo(
211205
() => true
212206
)
213207

214-
const getIds = (state) => state.data.map((el) => el.id)
208+
const getItems = (state) => state.data
215209

216210
const Main = () => {
217211
/**
218212
* @type {string[]}
219213
*/
220-
const ids = useStore(getIds, shallow)
214+
const items = useStore(getItems, shallow)
221215

222216
return (
223217
<div className="container">
224218
<Jumbotron />
225219
<table className="table table-hover table-striped test-data">
226220
<tbody>
227-
{ids.map((id, i) => (
228-
<Row key={id} itemId={id} />
221+
{items.map((item) => (
222+
<Row key={item.id} item={item} />
229223
))}
230224
</tbody>
231225
</table>

0 commit comments

Comments
 (0)