Skip to content

Commit a8c31f4

Browse files
Oblosystimdorr
authored andcommitted
Replace unnecessary lets with consts (#2931)
1 parent ee5c563 commit a8c31f4

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

docs/recipes/ReducingBoilerplate.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ You can always write a function that generates an action creator:
133133
```js
134134
function makeActionCreator(type, ...argNames) {
135135
return function (...args) {
136-
let action = { type }
136+
const action = { type }
137137
argNames.forEach((arg, index) => {
138138
action[argNames[index]] = args[index]
139139
})
@@ -198,7 +198,7 @@ import {
198198
class Posts extends Component {
199199
loadData(userId) {
200200
// Injected into props by React Redux `connect()` call:
201-
let { dispatch, posts } = this.props
201+
const { dispatch, posts } = this.props
202202

203203
if (posts[userId]) {
204204
// There is cached data! Don't do anything.
@@ -231,7 +231,7 @@ class Posts extends Component {
231231
return <p>Loading...</p>
232232
}
233233

234-
let posts = this.props.posts.map(post =>
234+
const posts = this.props.posts.map(post =>
235235
<Post post={post} key={post.id} />
236236
)
237237

@@ -262,7 +262,7 @@ Consider the code above rewritten with [redux-thunk](https://github.com/gaearon/
262262
export function loadPosts(userId) {
263263
// Interpreted by the thunk middleware:
264264
return function (dispatch, getState) {
265-
let { posts } = getState()
265+
const { posts } = getState()
266266
if (posts[userId]) {
267267
// There is cached data! Don't do anything.
268268
return
@@ -315,7 +315,7 @@ class Posts extends Component {
315315
return <p>Loading...</p>
316316
}
317317

318-
let posts = this.props.posts.map(post =>
318+
const posts = this.props.posts.map(post =>
319319
<Post post={post} key={post.id} />
320320
)
321321

@@ -461,7 +461,7 @@ Redux reduces the boilerplate of Flux stores considerably by describing the upda
461461
Consider this Flux store:
462462

463463
```js
464-
let _todos = []
464+
const _todos = []
465465

466466
const TodoStore = Object.assign({}, EventEmitter.prototype, {
467467
getAll() {
@@ -472,7 +472,7 @@ const TodoStore = Object.assign({}, EventEmitter.prototype, {
472472
AppDispatcher.register(function (action) {
473473
switch (action.type) {
474474
case ActionTypes.ADD_TODO:
475-
let text = action.text.trim()
475+
const text = action.text.trim()
476476
_todos.push(text)
477477
TodoStore.emitChange()
478478
}
@@ -487,7 +487,7 @@ With Redux, the same update logic can be described as a reducing function:
487487
export function todos(state = [], action) {
488488
switch (action.type) {
489489
case ActionTypes.ADD_TODO:
490-
let text = action.text.trim()
490+
const text = action.text.trim()
491491
return [...state, text]
492492
default:
493493
return state
@@ -506,7 +506,7 @@ Let's write a function that lets us express reducers as an object mapping from a
506506
```js
507507
export const todos = createReducer([], {
508508
[ActionTypes.ADD_TODO]: (state, action) => {
509-
let text = action.text.trim()
509+
const text = action.text.trim()
510510
return [...state, text]
511511
}
512512
})

0 commit comments

Comments
 (0)