{"action":"created","issue":{"url":"https://api.github.com/repos/baderahmed/react-native-customisable-switch/issues/12","repository_url":"https://api.github.com/repos/baderahmed/react-native-customisable-switch","labels_url":"https://api.github.com/repos/baderahmed/react-native-customisable-switch/issues/12/labels{/name}","comments_url":"https://api.github.com/repos/baderahmed/react-native-customisable-switch/issues/12/comments","events_url":"https://api.github.com/repos/baderahmed/react-native-customisable-switch/issues/12/events","html_url":"https://github.com/baderahmed/react-native-customisable-switch/issues/12","id":276924559,"number":12,"title":"Switch is not working with Redux","user":{"login":"mvsiva4u","id":17272240,"avatar_url":"https://avatars2.githubusercontent.com/u/17272240?v=4","gravatar_id":"","url":"https://api.github.com/users/mvsiva4u","html_url":"https://github.com/mvsiva4u","followers_url":"https://api.github.com/users/mvsiva4u/followers","following_url":"https://api.github.com/users/mvsiva4u/following{/other_user}","gists_url":"https://api.github.com/users/mvsiva4u/gists{/gist_id}","starred_url":"https://api.github.com/users/mvsiva4u/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mvsiva4u/subscriptions","organizations_url":"https://api.github.com/users/mvsiva4u/orgs","repos_url":"https://api.github.com/users/mvsiva4u/repos","events_url":"https://api.github.com/users/mvsiva4u/events{/privacy}","received_events_url":"https://api.github.com/users/mvsiva4u/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-11-27T07:31:49Z","updated_at":"2018-03-26T11:07:55Z","closed_at":null,"author_association":"NONE","body":"We used switch where the initial state set in Redux. but when entered the data and saving in local , If i'm fetching back the details it is not behaving as expected. Below is the code we have written.\r\n<Switch\r\n                value={this.state.address.sameas.value === 'N' ? false : true}\r\n                switchWidth={50}\r\n                switchHeight={25}\r\n                buttonWidth={25}\r\n                buttonHeight={25}\r\n                switchBorderColor={'rgba(0, 0, 0, 1)'}\r\n                activeBackgroundColor={'#009669'}\r\n                inactiveBackgroundColor={'#888888'}\r\n                buttonBorderColor={'rgba(0, 0, 0, 1)'}\r\n                buttonBorderWidth={1}\r\n                padding={false}\r\n                onChangeValue={sameas => {\r\n                  address.sameas.value = sameas ? 'Y' : 'N';\r\n                  this.setState({ address});\r\n                }}\r\n              />\r\n\r\nbelow is the way setting the state in redux.\r\n\r\nsameas:  {\r\n        value: 'N',\r\n        error: '',\r\n        enable: true\r\n    },"},"comment":{"url":"https://api.github.com/repos/baderahmed/react-native-customisable-switch/issues/comments/376129448","html_url":"https://github.com/baderahmed/react-native-customisable-switch/issues/12#issuecomment-376129448","issue_url":"https://api.github.com/repos/baderahmed/react-native-customisable-switch/issues/12","id":376129448,"user":{"login":"Stettinum","id":14040994,"avatar_url":"https://avatars2.githubusercontent.com/u/14040994?v=4","gravatar_id":"","url":"https://api.github.com/users/Stettinum","html_url":"https://github.com/Stettinum","followers_url":"https://api.github.com/users/Stettinum/followers","following_url":"https://api.github.com/users/Stettinum/following{/other_user}","gists_url":"https://api.github.com/users/Stettinum/gists{/gist_id}","starred_url":"https://api.github.com/users/Stettinum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Stettinum/subscriptions","organizations_url":"https://api.github.com/users/Stettinum/orgs","repos_url":"https://api.github.com/users/Stettinum/repos","events_url":"https://api.github.com/users/Stettinum/events{/privacy}","received_events_url":"https://api.github.com/users/Stettinum/received_events","type":"User","site_admin":false},"created_at":"2018-03-26T11:07:55Z","updated_at":"2018-03-26T11:07:55Z","author_association":"NONE","body":"hey did you find solution ? \r\nIf yes please just ignore it if not here you have a solution: \r\n\r\nIt's because that you probably have rendered your switch on start, at it's state is initailzed on start.\r\nAfter that you redux state is updated and props are received to you'r component and you try to update switch but switch has state initailized on constructor.\r\nSo in other words you only need to implement `componentWillReceiveProps` (switch.js file) method and set state of this switch in that method.\r\nIn real word example would be: \r\n`\r\n componentWillReceiveProps(nextProps) {\r\n    this.setState({\r\n      value: nextProps.value,\r\n      transformValue: new Animated.Value(nextProps.value ? this.transformValue : this.padding), //you need to remember about that\r\n      backgroundColor: new Animated.Value(nextProps.value ? 90 : -90),//you need to remember about that\r\n      buttonBackgroundColor: new Animated.Value(nextProps.value ? 90 : -90),//you need to remember about that\r\n    })\r\n }\r\n`\r\nand when it received props it will change its state.\r\nOfc you can also implement logic like `shouldComponentUpdate` but it's up to you. This basically works.\r\nRegards"}}
{"actor":{"display_login":"Stettinum"}}