回答編集履歴
1
テキスト修正
answer
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
こんにちは
|
2
2
|
|
3
|
-
[react-waypoint](https://github.com/civiccc/react-waypoint) を使ってみるのはいかがでしょうか?
|
3
|
+
[react-waypoint](https://github.com/civiccc/react-waypoint) を使ってみるのはいかがでしょうか? `yarn add react-waypoint` した後、以下のような修正になります。
|
4
4
|
|
5
|
-
```
|
5
|
+
```diff
|
6
|
-
import React from "react";
|
6
|
+
import React from "react";
|
7
|
-
import { Waypoint } from
|
7
|
+
+import { Waypoint } from 'react-waypoint';
|
8
|
-
import "./style.css";
|
8
|
+
import "./style.css";
|
9
|
-
|
9
|
+
|
10
|
-
const COLORS = ["red", "blue", "green", "yellow", "pink"];
|
10
|
+
+const COLORS = ["red", "blue", "green", "yellow", "pink"];
|
11
|
-
|
11
|
+
+
|
12
|
-
export default function App() {
|
12
|
+
export default function App() {
|
13
|
+
- const colorArray = ["red", "blue", "green", "yellow", "pink"];
|
13
|
-
const [colorArray, setColorArray] = React.useState(COLORS);
|
14
|
+
+ const [colorArray, setColorArray] = React.useState(COLORS);
|
14
|
-
|
15
|
+
+
|
15
|
-
const handleWaypointEnter = () => {
|
16
|
+
+ const handleWaypointEnter = () => {
|
16
|
-
setColorArray(colorArray.concat(COLORS));
|
17
|
+
+ setColorArray(colorArray.concat(COLORS));
|
17
|
-
}
|
18
|
+
+ }
|
18
|
-
|
19
|
+
+
|
19
|
-
|
20
|
+
const colorComponent = colorArray.map((item, key) => (
|
20
|
-
.map((item, key) => (
|
21
|
-
|
21
|
+
<div key={key}>
|
22
|
-
|
22
|
+
<div className={item} style={{ width: "200px", height: "200px" }} />
|
23
|
-
|
23
|
+
</div>
|
24
|
-
|
24
|
+
- ));
|
25
|
-
|
25
|
+
+ )).concat(<Waypoint key={-1} horizontal onEnter={handleWaypointEnter} />);
|
26
|
-
|
26
|
+
|
27
|
-
|
27
|
+
return (
|
28
28
|
<>
|
29
29
|
<p>this is loop content</p>
|
30
30
|
<div style={{ display: "flex", overflowX: "auto" }}>{colorComponent}</div>
|
@@ -33,7 +33,7 @@
|
|
33
33
|
}
|
34
34
|
|
35
35
|
```
|
36
|
-
`<Waypoint>` の `onEnter` が発生するたびに、`colorArray` に5色の配列を足していきます。以下は
|
36
|
+
仕組みとしては、`<Waypoint>` の `onEnter` が発生するたびに、`colorArray` に5色の配列を足していきます。以下はご質問にあったcodesandboxのコードをforkして、上記の修正を反映させたAppを動作確認するものです。
|
37
37
|
|
38
38
|
- **動作確認用codesandbox:** [https://codesandbox.io/s/q271097-20bym](https://codesandbox.io/s/q271097-20bym)
|
39
39
|
|