Skip to content

Commit 2322059

Browse files
committed
remove result intermediate state layer
1 parent 52d94b2 commit 2322059

1 file changed

Lines changed: 16 additions & 19 deletions

File tree

src/App.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const updatedIssue = (issue, newReaction) => {
8484
};
8585

8686
const updatedIssueInState = mutationResult => state => {
87-
const { issues } = state.result.organization.repository;
87+
const { issues } = state.organization.repository;
8888
const { reaction, subject } = mutationResult.data.data.addReaction;
8989

9090
const newReaction = { content: reaction.content, id: subject.id };
@@ -99,16 +99,13 @@ const updatedIssueInState = mutationResult => state => {
9999

100100
return {
101101
...state,
102-
result: {
103-
...state.result,
104-
organization: {
105-
...state.result.organization,
106-
repository: {
107-
...state.result.organization.repository,
108-
issues: {
109-
...state.result.organization.repository.issues,
110-
edges: updatedIssues,
111-
},
102+
organization: {
103+
...state.organization,
104+
repository: {
105+
...state.organization.repository,
106+
issues: {
107+
...state.organization.repository.issues,
108+
edges: updatedIssues,
112109
},
113110
},
114111
},
@@ -118,28 +115,28 @@ const updatedIssueInState = mutationResult => state => {
118115
class App extends Component {
119116
state = {
120117
input: 'the-road-to-learn-react/the-road-to-learn-react',
121-
result: null,
118+
organization: null,
122119
errors: null,
123120
};
124121

125122
componentDidMount() {
126-
this.onFetchGitHub(this.state.input);
123+
this.onFetchFromGitHub(this.state.input);
127124
}
128125

129126
onChange = event => {
130127
this.setState({ input: event.target.value });
131128
};
132129

133130
onSubmit = event => {
134-
this.onFetchGitHub(this.state.input);
131+
this.onFetchFromGitHub(this.state.input);
135132

136133
event.preventDefault();
137134
};
138135

139-
onFetchGitHub = input => {
136+
onFetchFromGitHub = input => {
140137
getIssuesOfRepository(input).then(result =>
141138
this.setState(() => ({
142-
result: result.data.data,
139+
organization: result.data.data.organization,
143140
errors: result.data.errors,
144141
})),
145142
);
@@ -152,7 +149,7 @@ class App extends Component {
152149
};
153150

154151
render() {
155-
const { input, result, errors } = this.state;
152+
const { input, organization, errors } = this.state;
156153

157154
return (
158155
<div>
@@ -174,9 +171,9 @@ class App extends Component {
174171

175172
<hr />
176173

177-
{result ? (
174+
{organization ? (
178175
<Organization
179-
organization={result.organization}
176+
organization={organization}
180177
errors={errors}
181178
onAddReactionToIssue={this.onAddReactionToIssue}
182179
/>

0 commit comments

Comments
 (0)