質問編集履歴

3

コードの追加

2020/05/13 07:44

投稿

kaoru_tujimiya
kaoru_tujimiya

スコア36

test CHANGED
File without changes
test CHANGED
@@ -25,127 +25,3 @@
25
25
  44 | // setPublishDate({ ...publishDate, [name]: value })
26
26
 
27
27
  ```
28
-
29
-
30
-
31
- ```react
32
-
33
- import React, { useState, useEffect } from 'react'
34
-
35
- import moment from 'moment'
36
-
37
- import { Select } from 'antd'
38
-
39
- const { Option } = Select
40
-
41
-
42
-
43
- const aaa = (props) => {
44
-
45
- const { state, setState } = props
46
-
47
- const [publishDate, setPublishDate] = useState({
48
-
49
- dateMonth: '',
50
-
51
- })
52
-
53
-
54
-
55
- const monthNumbers = [...Array(12).keys()].map((i) => ++i)
56
-
57
- const monthItems = monthNumbers.map((monthNumber) => (
58
-
59
- <Option value={('0' + monthNumber).slice(-2)}>
60
-
61
- {('0' + monthNumber).slice(-2)}
62
-
63
- </Option>
64
-
65
- ))
66
-
67
-
68
-
69
- useEffect(() => {
70
-
71
- const formated = moment(Number(state.publishedAt))
72
-
73
- .format('YYYY/MM/DD/HH/mm')
74
-
75
- .split('/')
76
-
77
- setPublishDate({
78
-
79
- dateMonth: formated[1],
80
-
81
- })
82
-
83
- // eslint-disable-next-line react-hooks/exhaustive-deps
84
-
85
- }, [])
86
-
87
-
88
-
89
- const onChange = (e) => {
90
-
91
- console.log(e)
92
-
93
- const { name, value } = e.target
94
-
95
- const tempDate = { ...publishDate, [name]: value }
96
-
97
- const formated = `${tempDate.dateMonth}`
98
-
99
- setPublishDate({ ...publishDate, [name]: value })
100
-
101
- setState({
102
-
103
- ...state,
104
-
105
- publishedAt: String(new Date(formated).getTime()),
106
-
107
- })
108
-
109
- }
110
-
111
-
112
-
113
- return (
114
-
115
- <>
116
-
117
- <label>
118
-
119
- <Select
120
-
121
- // name="dateMonth"
122
-
123
- value={publishDate.dateMonth}
124
-
125
- onChange={onChange}
126
-
127
- >
128
-
129
- {monthItems}
130
-
131
- </Select>
132
-
133
- </label>
134
-
135
-
136
-
137
- </>
138
-
139
- )
140
-
141
- }
142
-
143
-
144
-
145
-
146
-
147
- export default aaa
148
-
149
-
150
-
151
- ```

2

文字修正

2020/05/13 07:43

投稿

kaoru_tujimiya
kaoru_tujimiya

スコア36

test CHANGED
@@ -1 +1 @@
1
- React hookでセレクトボックス項目の切換の方法
1
+ Reactでセレクトボックス項目の切換の方法
test CHANGED
File without changes

1

追加

2020/05/11 05:47

投稿

kaoru_tujimiya
kaoru_tujimiya

スコア36

test CHANGED
@@ -1 +1 @@
1
- React hookで選択項目の切換の方法
1
+ React hookでセレクトボックス項目の切換の方法
test CHANGED
File without changes