Skip to content

Commit

Permalink
Replace unnecessary lets with consts (#2931)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oblosys authored and timdorr committed Apr 12, 2018
1 parent ee5c563 commit a8c31f4
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions docs/recipes/ReducingBoilerplate.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ You can always write a function that generates an action creator:
```js
function makeActionCreator(type, ...argNames) {
return function (...args) {
let action = { type }
const action = { type }
argNames.forEach((arg, index) => {
action[argNames[index]] = args[index]
})
Expand Down Expand Up @@ -198,7 +198,7 @@ import {
class Posts extends Component {
loadData(userId) {
// Injected into props by React Redux `connect()` call:
let { dispatch, posts } = this.props
const { dispatch, posts } = this.props

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

let posts = this.props.posts.map(post =>
const posts = this.props.posts.map(post =>
<Post post={post} key={post.id} />
)

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

let posts = this.props.posts.map(post =>
const posts = this.props.posts.map(post =>
<Post post={post} key={post.id} />
)

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

```js
let _todos = []
const _todos = []

const TodoStore = Object.assign({}, EventEmitter.prototype, {
getAll() {
Expand All @@ -472,7 +472,7 @@ const TodoStore = Object.assign({}, EventEmitter.prototype, {
AppDispatcher.register(function (action) {
switch (action.type) {
case ActionTypes.ADD_TODO:
let text = action.text.trim()
const text = action.text.trim()
_todos.push(text)
TodoStore.emitChange()
}
Expand All @@ -487,7 +487,7 @@ With Redux, the same update logic can be described as a reducing function:
export function todos(state = [], action) {
switch (action.type) {
case ActionTypes.ADD_TODO:
let text = action.text.trim()
const text = action.text.trim()
return [...state, text]
default:
return state
Expand All @@ -506,7 +506,7 @@ Let's write a function that lets us express reducers as an object mapping from a
```js
export const todos = createReducer([], {
[ActionTypes.ADD_TODO]: (state, action) => {
let text = action.text.trim()
const text = action.text.trim()
return [...state, text]
}
})
Expand Down

0 comments on commit a8c31f4

Please sign in to comment.