File tree Expand file tree Collapse file tree 4 files changed +46
-21
lines changed
components/usesyncexternalstore
domain/usesyncexternalstore/todolist
pages/usesyncexternalstore Expand file tree Collapse file tree 4 files changed +46
-21
lines changed Original file line number Diff line number Diff line change 11import PropTypes from 'prop-types'
22import Page from '@/common/layout/page'
3+ import Card from '@/common/ui/card'
4+ import TodoListComponentV2 from '@/domain/usesyncexternalstore/todolist'
35
46function UseSyncExternalStoreComponent ( {
5- todos,
67 addTodo,
78 deleteTodo
89} ) {
@@ -12,30 +13,26 @@ function UseSyncExternalStoreComponent ({
1213 UseSyncExternalStoreComponent
1314 </ h2 >
1415
15- { ( todos !== undefined ) &&
16- < div >
17- < ul >
18- { todos . map ( ( item , index ) => (
19- < li key = { index } >
20- < span > { item . text } </ span >
21- < span >
22- < button onClick = { ( ) => deleteTodo ( item . id ) } > [ X ]</ button >
23- </ span >
24- </ li >
25- ) ) }
26- </ ul >
27- </ div >
28- }
16+ < TodoListComponentV2
17+ deleteTodo = { deleteTodo }
18+ />
2919
30- < button onClick = { ( ) => addTodo ( ) } > Add Todo</ button >
20+ < button onClick = { ( ) => addTodo ( ) } >
21+ Add Todo
22+ </ button >
23+
24+ < br /> < br />
25+
26+ < Card >
27+ Hello
28+ </ Card >
3129 </ Page >
3230 )
3331}
3432
3533UseSyncExternalStoreComponent . propTypes = {
36- todos : PropTypes . array ,
3734 addTodo : PropTypes . func ,
38- deleteTodo : PropTypes . fun
35+ deleteTodo : PropTypes . func
3936}
4037
4138export default UseSyncExternalStoreComponent
Original file line number Diff line number Diff line change 1+ import PropTypes from 'prop-types'
2+ import useTodos from '@/lib/hooks/usetodo'
3+
4+ function TodoListComponentV2 ( {
5+ deleteTodo
6+ } ) {
7+ const { todos } = useTodos ( )
8+
9+ return (
10+ < ul style = { { marginTop : '24px' } } >
11+ { ( todos ) . map ( ( ( item , index ) => (
12+ < li key = { index } >
13+ < span > id: { item . id } , { item . text } </ span >
14+ < span >
15+ < button onClick = { ( ) => deleteTodo ( item . id ) } >
16+ [ x ]
17+ </ button >
18+ </ span >
19+ </ li >
20+ ) ) ) }
21+ </ ul >
22+ )
23+ }
24+
25+ TodoListComponentV2 . propTypes = {
26+ deleteTodo : PropTypes . func
27+ }
28+
29+ export default TodoListComponentV2
File renamed without changes.
Original file line number Diff line number Diff line change 11import UseSyncExternalStoreComponent from '@/components/usesyncexternalstore'
2- import useTodos from '@/domain/usesyncexternalstore/todostore '
2+ import useTodos from '@/lib/hooks/usetodo '
33
44function UseSyncExternalStore ( ) {
5- const { todos , addTodo, deleteTodo } = useTodos ( )
5+ const { addTodo, deleteTodo } = useTodos ( )
66
77 return (
88 < UseSyncExternalStoreComponent
9- todos = { todos }
109 addTodo = { addTodo }
1110 deleteTodo = { deleteTodo }
1211 />
You can’t perform that action at this time.
0 commit comments