-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapptemp
executable file
·165 lines (136 loc) · 4.69 KB
/
apptemp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import React, { useState, setState } from 'react';
import ReactDom from 'react-dom';
// useState 로 준 초기값을 제거
// setState 를 2개 하면 동시에 된다 첫번째꺼 후에 두번째거가 아니라.
//d
const initialStateComment = [{
commentValue: '',
postId: 0,
commentId:0,
commentArray: [],
}]
const initialStateList = [{
listValue: '1',
postId: -1,
}]
const App = () => {
const [ list, setList ] = useState(initialStateList);
const [ input, setInput ] = useState('');
let [ counter, setCounter ] = useState(0);
const { listValue, postId } = list
let [ counterReply, setCounterReply ] = useState(0);
const [ reply, setReply ] = useState('');
const [ replyList, setReplyList ] = useState(initialStateComment);
const [ comments, setComments ] = useState([]);
const onChange = e => {
setInput(e.target.value);
};
const onEditChange = (e) => {
setReply(e.target.value);
};
const onEdit= (Id ) => {
console.log(reply);
setCounterReply(counterReply+1);
console.log(postId)
// console.log(counter+1);
console.log(replyList.commentArray)
console.log(replyList[postId])
console.log(replyList)
console.log(replyList.filter(index => index.postId == Id))
const fuckyou = replyList.filter(index => index.postId == Id)
const array =[];
fuckyou.forEach(el => array.push(el.commentValue) )
setComments(array);
console.log(comments)
// setComments(replyList.filter(index => index.postId == Id).commentValue)
setReplyList([...replyList, {
commentValue: reply,
postId: Id,
commentId: counterReply,
commentArray: array,
}])
}
const onInsert = () => {
console.log(list)
console.log(list.postId)
// console.log(listItems)
console.log(list.listItems)
// console.log(listValue)
console.log(input)
setCounter(counter+1)
setList( [... list, { listValue: input, postId: counter}])
// setList({ ...listItems, input, postId: 0})
};
return (
<div>
<input type="text" value={input} onChange={onChange} id={0} />
<button onClick={onInsert}>Add</button>
<ul>
{list.map(Item=> (
<li key={Item.postId}>
{Item.listValue}
{/* <button type="button"
onClick={() => console.log('remove')}
>
Remove
</button> */}
<input type="text" value={reply[postId]} onChange={e => onEditChange(e, Item.postId)} id={Item.postId} />
<button type="button" id ={Item.postId}
onClick={() => onEdit(Item.postId)}
>
Reply
</button>
{comments[Item.postId]}
{replyList.map((replyItem,i) =>(
<div key = {i}>
{comments[Item.postId]}
</div>
))
}
</li>
))}
</ul>
</div>
);
};
export default App;
// const tasks = [
// { name : "name1", id: 0},
// { name : "name2", id: 1},
// ];
// // }
// const App = () => {
// // Declare a new state variable, which we'll call "count"
// const [state, setState] = useState([]);
// const [count, setCount] = useState([]);
// const [title, setTitle] = useState([]);
// console.log(title)
// console.log(state);
// // useEffect(() => {
// // fetchTasks({ state, setState });
// // }, []);
// return (
// <>
// <div>
// <p>You clicked {count} times</p>
// <button onClick={() => setCount(count + 1)}>
// Click me
// </button>
// <input type="text" value={title}
// onChange={e => setTitle(e.target.value)}
// />
// <button type="button"
// onClick={() =>setState(title) }
// >
// add
// </button>
// </div>
// <li>
// {state.map((value, index) => (
// <li key={index}>{value}</li>
// ))}
// </li>
// </>
// );
// }
// export default App