{"action":"created","issue":{"url":"https://api.github.com/repos/erikras/react-redux-universal-hot-example/issues/962","repository_url":"https://api.github.com/repos/erikras/react-redux-universal-hot-example","labels_url":"https://api.github.com/repos/erikras/react-redux-universal-hot-example/issues/962/labels{/name}","comments_url":"https://api.github.com/repos/erikras/react-redux-universal-hot-example/issues/962/comments","events_url":"https://api.github.com/repos/erikras/react-redux-universal-hot-example/issues/962/events","html_url":"https://github.com/erikras/react-redux-universal-hot-example/issues/962","id":136565956,"number":962,"title":"How to clear/remove state properties?","user":{"login":"realbugger","id":9424409,"avatar_url":"https://avatars2.githubusercontent.com/u/9424409?v=4","gravatar_id":"","url":"https://api.github.com/users/realbugger","html_url":"https://github.com/realbugger","followers_url":"https://api.github.com/users/realbugger/followers","following_url":"https://api.github.com/users/realbugger/following{/other_user}","gists_url":"https://api.github.com/users/realbugger/gists{/gist_id}","starred_url":"https://api.github.com/users/realbugger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realbugger/subscriptions","organizations_url":"https://api.github.com/users/realbugger/orgs","repos_url":"https://api.github.com/users/realbugger/repos","events_url":"https://api.github.com/users/realbugger/events{/privacy}","received_events_url":"https://api.github.com/users/realbugger/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-02-26T01:18:06Z","updated_at":"2018-02-01T20:11:58Z","closed_at":"2016-02-27T22:24:36Z","author_association":"NONE","body":"Still learning React JS and Redux, and found this boilerplate to be extremely helpful. Good job Erik!\n\nI'm wondering how to clear/remove a state property, say, state.data. Note that I don't want to just set state.data to null. I want to remove state.data property all together. The following code works for me.\n\n```\n.......\ncase CLEAR:\n      delete state.data;\n      return {\n        ...state,\n        loading: false,\n        loaded: false\n      };\n.......\n```\n\nHowever, my understanding is that state in Redux should not be mutated. Although it's working, doesn't it violate the immutable rule of Redux? Actually, I don't see any code in the example making copies of state object before changing it, like most other Redux implementation does (see below).\n\n```\n......\n  var newState = Object.assign({}, state);\n  newState.data= action.data;\n  return newState;\n......\n```\n\nSo how does the example code get away from the whole Object.assign thing? I must be missing something. Thanks.\n"},"comment":{"url":"https://api.github.com/repos/erikras/react-redux-universal-hot-example/issues/comments/362387506","html_url":"https://github.com/erikras/react-redux-universal-hot-example/issues/962#issuecomment-362387506","issue_url":"https://api.github.com/repos/erikras/react-redux-universal-hot-example/issues/962","id":362387506,"user":{"login":"waynebloss","id":623736,"avatar_url":"https://avatars1.githubusercontent.com/u/623736?v=4","gravatar_id":"","url":"https://api.github.com/users/waynebloss","html_url":"https://github.com/waynebloss","followers_url":"https://api.github.com/users/waynebloss/followers","following_url":"https://api.github.com/users/waynebloss/following{/other_user}","gists_url":"https://api.github.com/users/waynebloss/gists{/gist_id}","starred_url":"https://api.github.com/users/waynebloss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/waynebloss/subscriptions","organizations_url":"https://api.github.com/users/waynebloss/orgs","repos_url":"https://api.github.com/users/waynebloss/repos","events_url":"https://api.github.com/users/waynebloss/events{/privacy}","received_events_url":"https://api.github.com/users/waynebloss/received_events","type":"User","site_admin":false},"created_at":"2018-02-01T20:11:58Z","updated_at":"2018-02-01T20:11:58Z","author_association":"NONE","body":"You can use destructuring to remove the properties. \r\n\r\nHere is a function that I use in my validation reducers to return a valid field state after making sure that the validation passed. It removes the `invalid` and `error` fields from the given `fieldState` object.\r\n\r\n```js\r\nfunction validFieldState(fieldState) {\r\n  if (fieldState.invalid) {\r\n    const {\r\n      invalid: _invalid,    // <-- The `_invalid` and `_error` variables are never used.\r\n      error: _error,\r\n      ...nextFieldState,  // <-- This variable gets every prop except for `invalid` and `error`.\r\n    } = fieldState;\r\n    return nextFieldState;\r\n  }\r\n  return fieldState;\r\n}\r\n```\r\n\r\nThis is a common pattern used in React, to remove certain `props` before copying them to a child component.\r\n"}}
{"actor":{"display_login":"waynebloss"}}