Reducer에서 Json의 특정 Key값을 지우는 방법
2020. 8. 31. 22:37ㆍJavaScript/React
내가 사용하고있는 1번째 방법
businessInfo: _.omit(response,['user']),
index.html에
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/0.10.0/lodash.min.js"></script>
추가
2번째방법 reducer에서는 사용안될것으로 보임..
const original = {
foo: 'bar',
stack: 'overflow',
};
// If the name of the property to remove is constant
const { stack, ...withoutFirst } = original;
console.log(withoutFirst); // Will be { "foo": "bar" }
// If the name of the property to remove is from a variable
const key = 'stack'
const { [key]: value, ...withoutSecond } = original;
console.log(withoutSecond); // Will be { "foo": "bar" }
// To do a deep removal with property names from variables
const deep = {
foo: 'bar',
c: {
x: 1,
y: 2
}
};
const parentKey = 'c';
const childKey = 'y';
// Remove the 'c' element from original
const { [parentKey]: parentValue, ...noChild } = deep;
// Remove the 'y' from the 'c' element
const { [childKey]: removedValue, ...childWithout } = parentValue;
// Merge back together
const withoutThird = { ...noChild, [parentKey]: childWithout };
console.log(withoutThird); // Will be { "foo": "bar", "c": { "x": 1 } }
출처 : https://stackoverflow.com/questions/34401098/remove-a-property-in-an-object-immutably
'JavaScript > React' 카테고리의 다른 글
why state change dosen't (not) re render child component (0) | 2021.01.17 |
---|---|
[Material UI] react-slick Slide 이미지 dot customize (0) | 2020.12.29 |
[React] GraphQL + React + fetchMore infinite Scroll 페이지네이션 (0) | 2020.12.26 |
[Material UI] Typography vertical center 정렬 (0) | 2020.12.25 |
[React Error] React limits the number of nested updates to prevent infinite loops. (0) | 2020.09.06 |