// 배열 요소에 있는 0을 모두 뒤로 빼주는 함수
let test = [0,1,0,0,3,12]
const moveZeroes = nums => {
let zeroCnt = 0;
while(nums.indexOf(0)!==-1){
nums.splice(nums.indexOf(0),1);
zeroCnt ++
}
for (let i=0; i<zeroCnt; i++){
nums.push(0)
}
return nums
}
moveZeroes(test)
.productImage {
max-width: 220px;
position: relative;
.heartImg {
// float: left;
position: absolute;
top: 10px;
left: 10px;
width: 10%;
z-index: 10;
}
.frontShoesImg {
position: relative;
width: 100%;
z-index: 5;
}
.backShoesImg {
width: 100%;
position: absolute;
left: 0px;
z-index: 1;
}
}
.beforeExample{
width: 100px;
opacity: 1;
transition: width 0.2s ease-out;
transition: opacity 0.2s ease-out;
}
.afterExample{
width: 0px;
opacity: 0;
transition: width 0.2s ease-out;
transition: opacity 0.2s ease-out;
}
.heartImgEmpty {
position: absolute;
top: 10px;
left: 10px;
width: 10%;
z-index: 10;
transition: transform 0.2s ease-out;
&:hover {
transform: scale(1.2);
}
}
객체 표현식
매번 변하는 값은 state
변하지 않는 값은 const
변한 state 바로 확인하기
handleFilter = () => {
this.setState(
{
hideFilterVaild: !this.state.hideFilterVaild,
},
() => {
console.log(this.state.hideFilterVaild);
}
);
};
tolocaleString
숫자 쉼표{products.map((product) => {
const { id, src, name, price } = product;
return (
<ProductContainer
hideFilterValid={hideFilterVaild}
id={id}
src={src}
name={name}
price={Number(price).toLocaleString('en')}
/>
);
})}
export class ProductList extends React.Component {
constructor() {
super();
this.state = {
products: [],
hideFilterVaild: false,
preItems: 0,
items: 14,
};
}
infiniteScroll = () => {
let scrollHeight = Math.max(
document.documentElement.scrollHeight,
document.body.scrollHeight
);
let scrollTop = Math.max(
document.documentElement.scrollTop,
document.body.scrollTop
);
let clientHeight = document.documentElement.clientHeight;
if (scrollTop + clientHeight === scrollHeight) {
console.log("success");
this.setState({
preItems: this.state.items,
items: this.state.items + 14,
});
this.componentDidMount();
}
};
componentDidMount() {
fetch("http://localhost:3000/data/ProductList/Products.json", {
method: "GET",
})
.then((res) => res.json())
.then((res) => {
// 무한스크롤 기능 확인을 위한 임의 함수
let result = res.products.slice(this.state.preItems, this.state.items);
this.setState({
products: this.state.products.concat(result),
});
// 실제 데이터 받아오는 함수
// this.setState({
// products: this.state.products.concat(res.products)
// })
});
window.addEventListener("scroll", this.infiniteScroll);
}
render() {}