728x90
WARNING in [eslint]
src/components/views/MainPage/index.js
Line 241:24: Array.prototype.map() expects a return value from arrow function.
The error you're seeing, Array.prototype.map() expects a return value from arrow function
, occurs because the map
function is used incorrectly. The map
function expects a return value from the arrow function used within it. If you don't need to transform the array but just want to iterate over it, you should use forEach
instead of map
.
Here's how you can correct the code:
- Replace
map
withforEach
to avoid the error. - Ensure that you are returning a value if you decide to use
map
.
Here's the corrected version of your onClickTR
function:
const onClickTR = (data) => {
Axios.post(`${ADMIN_SERVER}/labelbyuserdate`, {
user_id: data.user_id,
date: data.date.replaceAll("-", "/"),
}).then((res) => {
if (res.status === 200) {
// console.log(res.data.data);
setSeries3([{ data: res.data.data }]);
}
});
var newSeriesData = [];
dataset.forEach((d) => {
if (d.user_id === data.user_id && d.date === data.date) {
newSeriesData.push({
x: d.x.toString(),
y: [
new Date(`${d.date} ${d.start}`).getTime(),
new Date(`${d.date} ${d.end}`).getTime(),
],
label: d.label,
});
}
});
setSeries4([{ data: newSeriesData }]);
};
Explanation:
- Replaced
map
withforEach
:map
is used for transforming each element of an array and returning a new array with the transformed elements.forEach
is used for iterating over each element of an array without returning a new array. Since you're not transforming the array but rather pushing elements intonewSeriesData
,forEach
is appropriate here.
- Corrected the iteration:
- The function now iterates over
dataset
withforEach
, pushing the filtered and formatted data intonewSeriesData
.
- The function now iterates over
This should resolve the error and ensure that the function behaves as expected.
728x90
'💻 Study > 웹' 카테고리의 다른 글
Nginx - Streamlit 프록시 설정 방법 (0) | 2024.08.30 |
---|---|
[Node.js] MySQL2 모듈 장기간 연결 문제 해결 (0) | 2024.07.02 |
[MySQL] java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver | MySQL JDBC Driver Not Found (0) | 2022.07.18 |
[netlify] Page Not Found Error (React Router) (1) | 2022.01.03 |
[Netlify] Treating warnings as errors because process.env.CI = true. (0) | 2022.01.03 |