diff --git a/.eslintrc.cjs b/.eslintrc.cjs
index d7cd5d68ffb..0f388f5c201 100644
--- a/.eslintrc.cjs
+++ b/.eslintrc.cjs
@@ -34,7 +34,7 @@ module.exports = {
],
'@typescript-eslint/consistent-type-imports': [
'error',
- { prefer: 'type-imports', disallowTypeAnnotations: false },
- ],
+ { prefer: 'type-imports', disallowTypeAnnotations: false }
+ ]
}
}
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
index 8cffa4e1cf7..28219ad1f49 100644
--- a/.github/ISSUE_TEMPLATE/config.yml
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -1,5 +1,5 @@
blank_issues_enabled: false
contact_links:
- - name: 🤔 Questions and Help
- url: https://redux.js.org/introduction/getting-started#help-and-discussion
- about: This is a bug tracker, not a support system. For usage questions, please use our support resources.
+ - name: 🤔 Questions and Help
+ url: https://redux.js.org/introduction/getting-started#help-and-discussion
+ about: This is a bug tracker, not a support system. For usage questions, please use our support resources.
diff --git a/README.md b/README.md
index c2cf0d3f4ba..719c592b9e2 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-#
Redux
+#
Redux
Redux is a predictable state container for JavaScript apps.
diff --git a/docs/api/combineReducers.md b/docs/api/combineReducers.md
index a015f4fae29..76668298909 100644
--- a/docs/api/combineReducers.md
+++ b/docs/api/combineReducers.md
@@ -130,7 +130,7 @@ export default combineReducers({
#### `App.js`
```js
-import { configureStore } from '@reduxjs/toolkit'
+import { configureStore } from '@reduxjs/toolkit'
import reducer from './reducers/index'
const store = configureStore({
diff --git a/docs/usage/WritingTests.mdx b/docs/usage/WritingTests.mdx
index 7c4ca003a72..d08b0a70a11 100644
--- a/docs/usage/WritingTests.mdx
+++ b/docs/usage/WritingTests.mdx
@@ -351,7 +351,7 @@ interface ExtendedRenderOptions extends Omit {
export function renderWithProviders(
ui: React.ReactElement,
- extendedRenderOptions: ExtendedRenderOptions = {},
+ extendedRenderOptions: ExtendedRenderOptions = {}
) {
const {
preloadedState = {},
@@ -367,7 +367,7 @@ export function renderWithProviders(
// Return an object with the store and all of RTL's query functions
return {
store,
- ...render(ui, { wrapper: Wrapper, ...renderOptions }),
+ ...render(ui, { wrapper: Wrapper, ...renderOptions })
}
}
```
diff --git a/docs/usage/migrating-to-modern-redux.mdx b/docs/usage/migrating-to-modern-redux.mdx
index 1f3e641e6e7..f87c8b807ac 100644
--- a/docs/usage/migrating-to-modern-redux.mdx
+++ b/docs/usage/migrating-to-modern-redux.mdx
@@ -130,7 +130,7 @@ This example shows several possible common tasks when setting up a Redux store:
None of these are _required_, but they do show up frequently in real-world codebases.
```js title="Custom Store Setup: src/app/store.js"
-import { configureStore, combineReducers} from '@reduxjs/toolkit'
+import { configureStore, combineReducers } from '@reduxjs/toolkit'
import {
persistStore,
persistReducer,
@@ -139,7 +139,7 @@ import {
PAUSE,
PERSIST,
PURGE,
- REGISTER,
+ REGISTER
} from 'redux-persist'
import storage from 'redux-persist/lib/storage'
import { PersistGate } from 'redux-persist/integration/react'
@@ -163,7 +163,7 @@ const rootReducer = combineReducers({
const persistConfig = {
key: 'root',
version: 1,
- storage,
+ storage
}
const persistedReducer = persistReducer(persistConfig, rootReducer)
@@ -175,12 +175,12 @@ const store = configureStore({
const middleware = getDefaultMiddleware({
// Pass in a custom `extra` argument to the thunk middleware
thunk: {
- extraArgument: {serviceLayer}
+ extraArgument: { serviceLayer }
},
// Customize the built-in serializability dev check
serializableCheck: {
- ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
- },
+ ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER]
+ }
}).concat(customMiddleware, api.middleware)
// Conditionally add another middleware in dev
@@ -191,9 +191,12 @@ const store = configureStore({
return middleware
},
// Turn off devtools in prod, or pass options in dev
- devTools: process.env.NODE_ENV === 'production' ? false : {
- stateSanitizer: stateSanitizerForDevtools
- }
+ devTools:
+ process.env.NODE_ENV === 'production'
+ ? false
+ : {
+ stateSanitizer: stateSanitizerForDevtools
+ }
})
```
@@ -817,7 +820,7 @@ export const store = createStore(rootReducer)
export type RootAction = TodoActions | CounterActions
// ❌ Common pattern: manually defining the root state type with each field
export interface RootState {
- todos: TodosState;
+ todos: TodosState
counter: CounterState
}
diff --git a/errors.json b/errors.json
index ac6da06ac50..3f0c8ad59e6 100644
--- a/errors.json
+++ b/errors.json
@@ -17,4 +17,4 @@
"15": "Dispatching while constructing your middleware is not allowed. Other middleware would not be applied to this dispatch.",
"16": "bindActionCreators expected an object or a function, but instead received: ''. Did you write \"import ActionCreators from\" instead of \"import * as ActionCreators from\"?",
"17": "Action \"type\" property must be a string. Instead, the actual type was: ''. Value was: '' (stringified)"
-}
\ No newline at end of file
+}
diff --git a/examples/async/public/index.html b/examples/async/public/index.html
index 76356722a69..3ee866aa9a9 100644
--- a/examples/async/public/index.html
+++ b/examples/async/public/index.html
@@ -1,8 +1,8 @@
-
+
-
-
+
+
Redux Async Example
diff --git a/examples/async/src/components/Picker.js b/examples/async/src/components/Picker.js
index 5ee3250ce67..7cb6ce651af 100644
--- a/examples/async/src/components/Picker.js
+++ b/examples/async/src/components/Picker.js
@@ -4,21 +4,18 @@ import PropTypes from 'prop-types'
const Picker = ({ value, onChange, options }) => (
{value}
-
)
Picker.propTypes = {
- options: PropTypes.arrayOf(
- PropTypes.string.isRequired
- ).isRequired,
+ options: PropTypes.arrayOf(PropTypes.string.isRequired).isRequired,
value: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired
}
diff --git a/examples/async/src/components/Posts.js b/examples/async/src/components/Posts.js
index 88f6cf263b4..21ecab636d3 100644
--- a/examples/async/src/components/Posts.js
+++ b/examples/async/src/components/Posts.js
@@ -1,11 +1,11 @@
import React from 'react'
import PropTypes from 'prop-types'
-const Posts = ({posts}) => (
+const Posts = ({ posts }) => (
- {posts.map((post, i) =>
+ {posts.map((post, i) => (
- {post.title}
- )}
+ ))}
)
diff --git a/examples/async/src/containers/App.js b/examples/async/src/containers/App.js
index a3006941905..710de7334a5 100644
--- a/examples/async/src/containers/App.js
+++ b/examples/async/src/containers/App.js
@@ -1,7 +1,11 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
-import { selectSubreddit, fetchPostsIfNeeded, invalidateSubreddit } from '../actions'
+import {
+ selectSubreddit,
+ fetchPostsIfNeeded,
+ invalidateSubreddit
+} from '../actions'
import Picker from '../components/Picker'
import Posts from '../components/Posts'
@@ -43,28 +47,32 @@ class App extends Component {
const isEmpty = posts.length === 0
return (
-
+
- {lastUpdated &&
+ {lastUpdated && (
- Last updated at {new Date(lastUpdated).toLocaleTimeString()}.
- {' '}
+ Last updated at {new Date(lastUpdated).toLocaleTimeString()}.{' '}
- }
- {!isFetching &&
-
- }
+ )}
+ {!isFetching && (
+
+ )}
- {isEmpty
- ? (isFetching ?
Loading...
:
Empty.
)
- :
- }
+ {isEmpty ? (
+ isFetching ? (
+
Loading...
+ ) : (
+
Empty.
+ )
+ ) : (
+
+ )}
)
}
diff --git a/examples/async/src/index.js b/examples/async/src/index.js
index 32b33a6b608..7bd47af1229 100644
--- a/examples/async/src/index.js
+++ b/examples/async/src/index.js
@@ -7,15 +7,12 @@ import { createLogger } from 'redux-logger'
import reducer from './reducers'
import App from './containers/App'
-const middleware = [ thunk ]
+const middleware = [thunk]
if (process.env.NODE_ENV !== 'production') {
middleware.push(createLogger())
}
-const store = createStore(
- reducer,
- applyMiddleware(...middleware)
-)
+const store = createStore(reducer, applyMiddleware(...middleware))
render(
diff --git a/examples/async/src/reducers/index.js b/examples/async/src/reducers/index.js
index 7f58bcd559a..c63a3d6f12d 100644
--- a/examples/async/src/reducers/index.js
+++ b/examples/async/src/reducers/index.js
@@ -1,7 +1,9 @@
import { combineReducers } from 'redux'
import {
- SELECT_SUBREDDIT, INVALIDATE_SUBREDDIT,
- REQUEST_POSTS, RECEIVE_POSTS
+ SELECT_SUBREDDIT,
+ INVALIDATE_SUBREDDIT,
+ REQUEST_POSTS,
+ RECEIVE_POSTS
} from '../actions'
const selectedSubreddit = (state = 'reactjs', action) => {
@@ -13,11 +15,14 @@ const selectedSubreddit = (state = 'reactjs', action) => {
}
}
-const posts = (state = {
- isFetching: false,
- didInvalidate: false,
- items: []
-}, action) => {
+const posts = (
+ state = {
+ isFetching: false,
+ didInvalidate: false,
+ items: []
+ },
+ action
+) => {
switch (action.type) {
case INVALIDATE_SUBREDDIT:
return {
@@ -43,7 +48,7 @@ const posts = (state = {
}
}
-const postsBySubreddit = (state = { }, action) => {
+const postsBySubreddit = (state = {}, action) => {
switch (action.type) {
case INVALIDATE_SUBREDDIT:
case RECEIVE_POSTS:
diff --git a/examples/counter-ts/src/App.test.tsx b/examples/counter-ts/src/App.test.tsx
index 659cc13d3bb..33e2b79bd87 100644
--- a/examples/counter-ts/src/App.test.tsx
+++ b/examples/counter-ts/src/App.test.tsx
@@ -1,15 +1,15 @@
-import React from 'react';
-import { render } from '@testing-library/react';
-import { Provider } from 'react-redux';
-import { store } from './app/store';
-import App from './App';
+import React from 'react'
+import { render } from '@testing-library/react'
+import { Provider } from 'react-redux'
+import { store } from './app/store'
+import App from './App'
test('renders learn react link', () => {
const { getByText } = render(
- );
+ )
- expect(getByText(/learn/i)).toBeInTheDocument();
-});
+ expect(getByText(/learn/i)).toBeInTheDocument()
+})
diff --git a/examples/counter-ts/src/app/hooks.ts b/examples/counter-ts/src/app/hooks.ts
index b0d4821e0b9..02834535077 100644
--- a/examples/counter-ts/src/app/hooks.ts
+++ b/examples/counter-ts/src/app/hooks.ts
@@ -3,4 +3,4 @@ import type { AppDispatch, RootState } from './store'
// Use throughout your app instead of plain `useDispatch` and `useSelector`
export const useAppDispatch = useDispatch.withTypes()
-export const useAppSelector = useSelector.withTypes()
\ No newline at end of file
+export const useAppSelector = useSelector.withTypes()
diff --git a/examples/counter-ts/src/app/store.ts b/examples/counter-ts/src/app/store.ts
index 133ff34eec1..8c4118ebd9f 100644
--- a/examples/counter-ts/src/app/store.ts
+++ b/examples/counter-ts/src/app/store.ts
@@ -1,17 +1,17 @@
-import { configureStore, ThunkAction, Action } from '@reduxjs/toolkit';
-import counterReducer from '../features/counter/counterSlice';
+import { configureStore, ThunkAction, Action } from '@reduxjs/toolkit'
+import counterReducer from '../features/counter/counterSlice'
export const store = configureStore({
reducer: {
- counter: counterReducer,
- },
-});
+ counter: counterReducer
+ }
+})
-export type AppDispatch = typeof store.dispatch;
-export type RootState = ReturnType;
+export type AppDispatch = typeof store.dispatch
+export type RootState = ReturnType
export type AppThunk = ThunkAction<
ReturnType,
RootState,
unknown,
Action
->;
+>
diff --git a/examples/counter-ts/src/features/counter/Counter.tsx b/examples/counter-ts/src/features/counter/Counter.tsx
index ece5191bae3..222d6074c4c 100644
--- a/examples/counter-ts/src/features/counter/Counter.tsx
+++ b/examples/counter-ts/src/features/counter/Counter.tsx
@@ -1,22 +1,22 @@
-import React, { useState } from 'react';
+import React, { useState } from 'react'
-import { useAppSelector, useAppDispatch } from '../../app/hooks';
+import { useAppSelector, useAppDispatch } from '../../app/hooks'
import {
decrement,
increment,
incrementByAmount,
incrementAsync,
incrementIfOdd,
- selectCount,
-} from './counterSlice';
-import styles from './Counter.module.css';
+ selectCount
+} from './counterSlice'
+import styles from './Counter.module.css'
export function Counter() {
- const count = useAppSelector(selectCount);
- const dispatch = useAppDispatch();
- const [incrementAmount, setIncrementAmount] = useState('2');
+ const count = useAppSelector(selectCount)
+ const dispatch = useAppDispatch()
+ const [incrementAmount, setIncrementAmount] = useState('2')
- const incrementValue = Number(incrementAmount) || 0;
+ const incrementValue = Number(incrementAmount) || 0
return (
@@ -42,7 +42,7 @@ export function Counter() {
className={styles.textbox}
aria-label="Set increment amount"
value={incrementAmount}
- onChange={(e) => setIncrementAmount(e.target.value)}
+ onChange={e => setIncrementAmount(e.target.value)}
/>
- );
+ )
}
diff --git a/examples/counter-ts/src/features/counter/counterAPI.ts b/examples/counter-ts/src/features/counter/counterAPI.ts
index 0a9cdd31b9b..f0dcc12f1da 100644
--- a/examples/counter-ts/src/features/counter/counterAPI.ts
+++ b/examples/counter-ts/src/features/counter/counterAPI.ts
@@ -1,6 +1,6 @@
// A mock function to mimic making an async request for data
export function fetchCount(amount = 1) {
- return new Promise<{ data: number }>((resolve) =>
+ return new Promise<{ data: number }>(resolve =>
setTimeout(() => resolve({ data: amount }), 500)
- );
+ )
}
diff --git a/examples/counter-ts/src/features/counter/counterSlice.spec.ts b/examples/counter-ts/src/features/counter/counterSlice.spec.ts
index 098163b9ad9..82049d5c45b 100644
--- a/examples/counter-ts/src/features/counter/counterSlice.spec.ts
+++ b/examples/counter-ts/src/features/counter/counterSlice.spec.ts
@@ -2,33 +2,33 @@ import counterReducer, {
CounterState,
increment,
decrement,
- incrementByAmount,
-} from './counterSlice';
+ incrementByAmount
+} from './counterSlice'
describe('counter reducer', () => {
const initialState: CounterState = {
value: 3,
- status: 'idle',
- };
+ status: 'idle'
+ }
it('should handle initial state', () => {
expect(counterReducer(undefined, { type: 'unknown' })).toEqual({
value: 0,
- status: 'idle',
- });
- });
+ status: 'idle'
+ })
+ })
it('should handle increment', () => {
- const actual = counterReducer(initialState, increment());
- expect(actual.value).toEqual(4);
- });
+ const actual = counterReducer(initialState, increment())
+ expect(actual.value).toEqual(4)
+ })
it('should handle decrement', () => {
- const actual = counterReducer(initialState, decrement());
- expect(actual.value).toEqual(2);
- });
+ const actual = counterReducer(initialState, decrement())
+ expect(actual.value).toEqual(2)
+ })
it('should handle incrementByAmount', () => {
- const actual = counterReducer(initialState, incrementByAmount(2));
- expect(actual.value).toEqual(5);
- });
-});
+ const actual = counterReducer(initialState, incrementByAmount(2))
+ expect(actual.value).toEqual(5)
+ })
+})
diff --git a/examples/counter-ts/src/features/counter/counterSlice.ts b/examples/counter-ts/src/features/counter/counterSlice.ts
index 015dca0aaea..0c30ed857e1 100644
--- a/examples/counter-ts/src/features/counter/counterSlice.ts
+++ b/examples/counter-ts/src/features/counter/counterSlice.ts
@@ -1,16 +1,16 @@
-import { createAsyncThunk, createSlice, PayloadAction } from '@reduxjs/toolkit';
-import { RootState, AppThunk } from '../../app/store';
-import { fetchCount } from './counterAPI';
+import { createAsyncThunk, createSlice, PayloadAction } from '@reduxjs/toolkit'
+import { RootState, AppThunk } from '../../app/store'
+import { fetchCount } from './counterAPI'
export interface CounterState {
- value: number;
- status: 'idle' | 'loading' | 'failed';
+ value: number
+ status: 'idle' | 'loading' | 'failed'
}
const initialState: CounterState = {
value: 0,
- status: 'idle',
-};
+ status: 'idle'
+}
// The function below is called a thunk and allows us to perform async logic. It
// can be dispatched like a regular action: `dispatch(incrementAsync(10))`. This
@@ -20,65 +20,65 @@ const initialState: CounterState = {
export const incrementAsync = createAsyncThunk(
'counter/fetchCount',
async (amount: number) => {
- const response = await fetchCount(amount);
+ const response = await fetchCount(amount)
// The value we return becomes the `fulfilled` action payload
- return response.data;
+ return response.data
}
-);
+)
export const counterSlice = createSlice({
name: 'counter',
initialState,
// The `reducers` field lets us define reducers and generate associated actions
reducers: {
- increment: (state) => {
+ increment: state => {
// Redux Toolkit allows us to write "mutating" logic in reducers. It
// doesn't actually mutate the state because it uses the Immer library,
// which detects changes to a "draft state" and produces a brand new
// immutable state based off those changes
- state.value += 1;
+ state.value += 1
},
- decrement: (state) => {
- state.value -= 1;
+ decrement: state => {
+ state.value -= 1
},
// Use the PayloadAction type to declare the contents of `action.payload`
incrementByAmount: (state, action: PayloadAction) => {
- state.value += action.payload;
- },
+ state.value += action.payload
+ }
},
// The `extraReducers` field lets the slice handle actions defined elsewhere,
// including actions generated by createAsyncThunk or in other slices.
- extraReducers: (builder) => {
+ extraReducers: builder => {
builder
- .addCase(incrementAsync.pending, (state) => {
- state.status = 'loading';
+ .addCase(incrementAsync.pending, state => {
+ state.status = 'loading'
})
.addCase(incrementAsync.fulfilled, (state, action) => {
- state.status = 'idle';
- state.value += action.payload;
+ state.status = 'idle'
+ state.value += action.payload
})
- .addCase(incrementAsync.rejected, (state) => {
- state.status = 'failed';
- });
- },
-});
+ .addCase(incrementAsync.rejected, state => {
+ state.status = 'failed'
+ })
+ }
+})
-export const { increment, decrement, incrementByAmount } = counterSlice.actions;
+export const { increment, decrement, incrementByAmount } = counterSlice.actions
// The function below is called a selector and allows us to select a value from
// the state. Selectors can also be defined inline where they're used instead of
// in the slice file. For example: `useSelector((state: RootState) => state.counter.value)`
-export const selectCount = (state: RootState) => state.counter.value;
+export const selectCount = (state: RootState) => state.counter.value
// We can also write thunks by hand, which may contain both sync and async logic.
// Here's an example of conditionally dispatching actions based on current state.
export const incrementIfOdd =
(amount: number): AppThunk =>
(dispatch, getState) => {
- const currentValue = selectCount(getState());
+ const currentValue = selectCount(getState())
if (currentValue % 2 === 1) {
- dispatch(incrementByAmount(amount));
+ dispatch(incrementByAmount(amount))
}
- };
+ }
-export default counterSlice.reducer;
+export default counterSlice.reducer
diff --git a/examples/counter-ts/src/index.tsx b/examples/counter-ts/src/index.tsx
index 0e6466fa15c..c920ec95bc1 100644
--- a/examples/counter-ts/src/index.tsx
+++ b/examples/counter-ts/src/index.tsx
@@ -1,13 +1,13 @@
-import React from 'react';
-import { createRoot } from 'react-dom/client';
-import { Provider } from 'react-redux';
-import { store } from './app/store';
-import App from './App';
-import reportWebVitals from './reportWebVitals';
-import './index.css';
+import React from 'react'
+import { createRoot } from 'react-dom/client'
+import { Provider } from 'react-redux'
+import { store } from './app/store'
+import App from './App'
+import reportWebVitals from './reportWebVitals'
+import './index.css'
-const container = document.getElementById('root')!;
-const root = createRoot(container);
+const container = document.getElementById('root')!
+const root = createRoot(container)
root.render(
@@ -15,9 +15,9 @@ root.render(
-);
+)
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
-reportWebVitals();
+reportWebVitals()
diff --git a/examples/counter-ts/src/reportWebVitals.ts b/examples/counter-ts/src/reportWebVitals.ts
index 49a2a16e0fb..57a24a21eae 100644
--- a/examples/counter-ts/src/reportWebVitals.ts
+++ b/examples/counter-ts/src/reportWebVitals.ts
@@ -1,15 +1,15 @@
-import { ReportHandler } from 'web-vitals';
+import { ReportHandler } from 'web-vitals'
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
- getCLS(onPerfEntry);
- getFID(onPerfEntry);
- getFCP(onPerfEntry);
- getLCP(onPerfEntry);
- getTTFB(onPerfEntry);
- });
+ getCLS(onPerfEntry)
+ getFID(onPerfEntry)
+ getFCP(onPerfEntry)
+ getLCP(onPerfEntry)
+ getTTFB(onPerfEntry)
+ })
}
-};
+}
-export default reportWebVitals;
+export default reportWebVitals
diff --git a/examples/counter-ts/tsconfig.json b/examples/counter-ts/tsconfig.json
index a273b0cfc0e..9d379a3c4af 100644
--- a/examples/counter-ts/tsconfig.json
+++ b/examples/counter-ts/tsconfig.json
@@ -1,11 +1,7 @@
{
"compilerOptions": {
"target": "es5",
- "lib": [
- "dom",
- "dom.iterable",
- "esnext"
- ],
+ "lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
@@ -20,7 +16,5 @@
"noEmit": true,
"jsx": "react-jsx"
},
- "include": [
- "src"
- ]
+ "include": ["src"]
}
diff --git a/examples/counter-vanilla/index.html b/examples/counter-vanilla/index.html
index 61409c88dc8..f5d510fd5f9 100644
--- a/examples/counter-vanilla/index.html
+++ b/examples/counter-vanilla/index.html
@@ -41,24 +41,28 @@
render()
store.subscribe(render)
- document.getElementById('increment')
+ document
+ .getElementById('increment')
.addEventListener('click', function () {
store.dispatch({ type: 'INCREMENT' })
})
- document.getElementById('decrement')
+ document
+ .getElementById('decrement')
.addEventListener('click', function () {
store.dispatch({ type: 'DECREMENT' })
})
- document.getElementById('incrementIfOdd')
+ document
+ .getElementById('incrementIfOdd')
.addEventListener('click', function () {
if (store.getState() % 2 !== 0) {
store.dispatch({ type: 'INCREMENT' })
}
})
- document.getElementById('incrementAsync')
+ document
+ .getElementById('incrementAsync')
.addEventListener('click', function () {
setTimeout(function () {
store.dispatch({ type: 'INCREMENT' })
diff --git a/examples/counter/src/App.test.js b/examples/counter/src/App.test.js
index 980638bdf3b..527874cee80 100644
--- a/examples/counter/src/App.test.js
+++ b/examples/counter/src/App.test.js
@@ -1,15 +1,15 @@
-import React from 'react';
-import { render, screen } from '@testing-library/react';
-import { Provider } from 'react-redux';
-import { store } from './app/store';
-import App from './App';
+import React from 'react'
+import { render, screen } from '@testing-library/react'
+import { Provider } from 'react-redux'
+import { store } from './app/store'
+import App from './App'
test('renders learn react link', () => {
render(
- );
+ )
- expect(screen.getByText(/learn/i)).toBeInTheDocument();
-});
+ expect(screen.getByText(/learn/i)).toBeInTheDocument()
+})
diff --git a/examples/counter/src/app/store.js b/examples/counter/src/app/store.js
index 9eca6d24b1e..b7eca242d53 100644
--- a/examples/counter/src/app/store.js
+++ b/examples/counter/src/app/store.js
@@ -1,8 +1,8 @@
-import { configureStore } from '@reduxjs/toolkit';
-import counterReducer from '../features/counter/counterSlice';
+import { configureStore } from '@reduxjs/toolkit'
+import counterReducer from '../features/counter/counterSlice'
export const store = configureStore({
reducer: {
- counter: counterReducer,
- },
-});
+ counter: counterReducer
+ }
+})
diff --git a/examples/counter/src/features/counter/Counter.js b/examples/counter/src/features/counter/Counter.js
index 772a6bafeff..122d4cffb0e 100644
--- a/examples/counter/src/features/counter/Counter.js
+++ b/examples/counter/src/features/counter/Counter.js
@@ -1,21 +1,21 @@
-import React, { useState } from 'react';
-import { useSelector, useDispatch } from 'react-redux';
+import React, { useState } from 'react'
+import { useSelector, useDispatch } from 'react-redux'
import {
decrement,
increment,
incrementByAmount,
incrementAsync,
incrementIfOdd,
- selectCount,
-} from './counterSlice';
-import styles from './Counter.module.css';
+ selectCount
+} from './counterSlice'
+import styles from './Counter.module.css'
export function Counter() {
- const count = useSelector(selectCount);
- const dispatch = useDispatch();
- const [incrementAmount, setIncrementAmount] = useState('2');
+ const count = useSelector(selectCount)
+ const dispatch = useDispatch()
+ const [incrementAmount, setIncrementAmount] = useState('2')
- const incrementValue = Number(incrementAmount) || 0;
+ const incrementValue = Number(incrementAmount) || 0
return (
@@ -41,7 +41,7 @@ export function Counter() {
className={styles.textbox}
aria-label="Set increment amount"
value={incrementAmount}
- onChange={(e) => setIncrementAmount(e.target.value)}
+ onChange={e => setIncrementAmount(e.target.value)}
/>
- );
+ )
}
diff --git a/examples/counter/src/features/counter/counterAPI.js b/examples/counter/src/features/counter/counterAPI.js
index cc9b4a44238..da8f77cf424 100644
--- a/examples/counter/src/features/counter/counterAPI.js
+++ b/examples/counter/src/features/counter/counterAPI.js
@@ -1,6 +1,6 @@
// A mock function to mimic making an async request for data
export function fetchCount(amount = 1) {
- return new Promise((resolve) =>
+ return new Promise(resolve =>
setTimeout(() => resolve({ data: amount }), 500)
- );
+ )
}
diff --git a/examples/counter/src/features/counter/counterSlice.js b/examples/counter/src/features/counter/counterSlice.js
index 8dc4b5cff7b..35c666c8046 100644
--- a/examples/counter/src/features/counter/counterSlice.js
+++ b/examples/counter/src/features/counter/counterSlice.js
@@ -1,10 +1,10 @@
-import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
-import { fetchCount } from './counterAPI';
+import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'
+import { fetchCount } from './counterAPI'
const initialState = {
value: 0,
- status: 'idle',
-};
+ status: 'idle'
+}
// The function below is called a thunk and allows us to perform async logic. It
// can be dispatched like a regular action: `dispatch(incrementAsync(10))`. This
@@ -13,61 +13,61 @@ const initialState = {
// typically used to make async requests.
export const incrementAsync = createAsyncThunk(
'counter/fetchCount',
- async (amount) => {
- const response = await fetchCount(amount);
+ async amount => {
+ const response = await fetchCount(amount)
// The value we return becomes the `fulfilled` action payload
- return response.data;
+ return response.data
}
-);
+)
export const counterSlice = createSlice({
name: 'counter',
initialState,
// The `reducers` field lets us define reducers and generate associated actions
reducers: {
- increment: (state) => {
+ increment: state => {
// Redux Toolkit allows us to write "mutating" logic in reducers. It
// doesn't actually mutate the state because it uses the Immer library,
// which detects changes to a "draft state" and produces a brand new
// immutable state based off those changes
- state.value += 1;
+ state.value += 1
},
- decrement: (state) => {
- state.value -= 1;
+ decrement: state => {
+ state.value -= 1
},
// Use the PayloadAction type to declare the contents of `action.payload`
incrementByAmount: (state, action) => {
- state.value += action.payload;
- },
+ state.value += action.payload
+ }
},
// The `extraReducers` field lets the slice handle actions defined elsewhere,
// including actions generated by createAsyncThunk or in other slices.
- extraReducers: (builder) => {
+ extraReducers: builder => {
builder
- .addCase(incrementAsync.pending, (state) => {
- state.status = 'loading';
+ .addCase(incrementAsync.pending, state => {
+ state.status = 'loading'
})
.addCase(incrementAsync.fulfilled, (state, action) => {
- state.status = 'idle';
- state.value += action.payload;
- });
- },
-});
+ state.status = 'idle'
+ state.value += action.payload
+ })
+ }
+})
-export const { increment, decrement, incrementByAmount } = counterSlice.actions;
+export const { increment, decrement, incrementByAmount } = counterSlice.actions
// The function below is called a selector and allows us to select a value from
// the state. Selectors can also be defined inline where they're used instead of
// in the slice file. For example: `useSelector((state: RootState) => state.counter.value)`
-export const selectCount = (state) => state.counter.value;
+export const selectCount = state => state.counter.value
// We can also write thunks by hand, which may contain both sync and async logic.
// Here's an example of conditionally dispatching actions based on current state.
-export const incrementIfOdd = (amount) => (dispatch, getState) => {
- const currentValue = selectCount(getState());
+export const incrementIfOdd = amount => (dispatch, getState) => {
+ const currentValue = selectCount(getState())
if (currentValue % 2 === 1) {
- dispatch(incrementByAmount(amount));
+ dispatch(incrementByAmount(amount))
}
-};
+}
-export default counterSlice.reducer;
+export default counterSlice.reducer
diff --git a/examples/counter/src/features/counter/counterSlice.spec.js b/examples/counter/src/features/counter/counterSlice.spec.js
index c1fed2ce59e..8e7b34416c8 100644
--- a/examples/counter/src/features/counter/counterSlice.spec.js
+++ b/examples/counter/src/features/counter/counterSlice.spec.js
@@ -1,33 +1,33 @@
import counterReducer, {
increment,
decrement,
- incrementByAmount,
-} from './counterSlice';
+ incrementByAmount
+} from './counterSlice'
describe('counter reducer', () => {
const initialState = {
value: 3,
- status: 'idle',
- };
+ status: 'idle'
+ }
it('should handle initial state', () => {
expect(counterReducer(undefined, { type: 'unknown' })).toEqual({
value: 0,
- status: 'idle',
- });
- });
+ status: 'idle'
+ })
+ })
it('should handle increment', () => {
- const actual = counterReducer(initialState, increment());
- expect(actual.value).toEqual(4);
- });
+ const actual = counterReducer(initialState, increment())
+ expect(actual.value).toEqual(4)
+ })
it('should handle decrement', () => {
- const actual = counterReducer(initialState, decrement());
- expect(actual.value).toEqual(2);
- });
+ const actual = counterReducer(initialState, decrement())
+ expect(actual.value).toEqual(2)
+ })
it('should handle incrementByAmount', () => {
- const actual = counterReducer(initialState, incrementByAmount(2));
- expect(actual.value).toEqual(5);
- });
-});
+ const actual = counterReducer(initialState, incrementByAmount(2))
+ expect(actual.value).toEqual(5)
+ })
+})
diff --git a/examples/counter/src/index.js b/examples/counter/src/index.js
index 732a8cc84af..25568a01f04 100644
--- a/examples/counter/src/index.js
+++ b/examples/counter/src/index.js
@@ -1,13 +1,13 @@
-import React from 'react';
-import { createRoot } from 'react-dom/client';
-import { Provider } from 'react-redux';
-import { store } from './app/store';
-import App from './App';
-import reportWebVitals from './reportWebVitals';
-import './index.css';
+import React from 'react'
+import { createRoot } from 'react-dom/client'
+import { Provider } from 'react-redux'
+import { store } from './app/store'
+import App from './App'
+import reportWebVitals from './reportWebVitals'
+import './index.css'
-const container = document.getElementById('root');
-const root = createRoot(container);
+const container = document.getElementById('root')
+const root = createRoot(container)
root.render(
@@ -15,9 +15,9 @@ root.render(
-);
+)
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
-reportWebVitals();
+reportWebVitals()
diff --git a/examples/counter/src/reportWebVitals.js b/examples/counter/src/reportWebVitals.js
index 5253d3ad9e6..9381231d219 100644
--- a/examples/counter/src/reportWebVitals.js
+++ b/examples/counter/src/reportWebVitals.js
@@ -1,13 +1,13 @@
const reportWebVitals = onPerfEntry => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
- getCLS(onPerfEntry);
- getFID(onPerfEntry);
- getFCP(onPerfEntry);
- getLCP(onPerfEntry);
- getTTFB(onPerfEntry);
- });
+ getCLS(onPerfEntry)
+ getFID(onPerfEntry)
+ getFCP(onPerfEntry)
+ getLCP(onPerfEntry)
+ getTTFB(onPerfEntry)
+ })
}
-};
+}
-export default reportWebVitals;
+export default reportWebVitals
diff --git a/examples/real-world/public/index.html b/examples/real-world/public/index.html
index 72e10e94c6c..75e9a53d7da 100644
--- a/examples/real-world/public/index.html
+++ b/examples/real-world/public/index.html
@@ -1,8 +1,8 @@
-
+
-
-
+
+
React App
diff --git a/examples/real-world/src/actions/index.js b/examples/real-world/src/actions/index.js
index b57ae627bd0..20bb3f4c99b 100644
--- a/examples/real-world/src/actions/index.js
+++ b/examples/real-world/src/actions/index.js
@@ -8,7 +8,7 @@ export const USER_FAILURE = 'USER_FAILURE'
// Relies on the custom API middleware defined in ../middleware/api.js.
const fetchUser = login => ({
[CALL_API]: {
- types: [ USER_REQUEST, USER_SUCCESS, USER_FAILURE ],
+ types: [USER_REQUEST, USER_SUCCESS, USER_FAILURE],
endpoint: `users/${login}`,
schema: Schemas.USER
}
@@ -16,15 +16,17 @@ const fetchUser = login => ({
// Fetches a single user from Github API unless it is cached.
// Relies on Redux Thunk middleware.
-export const loadUser = (login, requiredFields = []) => (dispatch, getState) => {
- const user = getState().entities.users[login]
- if (user && requiredFields.every(key => user.hasOwnProperty(key))) {
- return null
+export const loadUser =
+ (login, requiredFields = []) =>
+ (dispatch, getState) => {
+ const user = getState().entities.users[login]
+ if (user && requiredFields.every(key => user.hasOwnProperty(key))) {
+ return null
+ }
+
+ return dispatch(fetchUser(login))
}
- return dispatch(fetchUser(login))
-}
-
export const REPO_REQUEST = 'REPO_REQUEST'
export const REPO_SUCCESS = 'REPO_SUCCESS'
export const REPO_FAILURE = 'REPO_FAILURE'
@@ -33,7 +35,7 @@ export const REPO_FAILURE = 'REPO_FAILURE'
// Relies on the custom API middleware defined in ../middleware/api.js.
const fetchRepo = fullName => ({
[CALL_API]: {
- types: [ REPO_REQUEST, REPO_SUCCESS, REPO_FAILURE ],
+ types: [REPO_REQUEST, REPO_SUCCESS, REPO_FAILURE],
endpoint: `repos/${fullName}`,
schema: Schemas.REPO
}
@@ -41,15 +43,17 @@ const fetchRepo = fullName => ({
// Fetches a single repository from Github API unless it is cached.
// Relies on Redux Thunk middleware.
-export const loadRepo = (fullName, requiredFields = []) => (dispatch, getState) => {
- const repo = getState().entities.repos[fullName]
- if (repo && requiredFields.every(key => repo.hasOwnProperty(key))) {
- return null
+export const loadRepo =
+ (fullName, requiredFields = []) =>
+ (dispatch, getState) => {
+ const repo = getState().entities.repos[fullName]
+ if (repo && requiredFields.every(key => repo.hasOwnProperty(key))) {
+ return null
+ }
+
+ return dispatch(fetchRepo(fullName))
}
- return dispatch(fetchRepo(fullName))
-}
-
export const STARRED_REQUEST = 'STARRED_REQUEST'
export const STARRED_SUCCESS = 'STARRED_SUCCESS'
export const STARRED_FAILURE = 'STARRED_FAILURE'
@@ -59,7 +63,7 @@ export const STARRED_FAILURE = 'STARRED_FAILURE'
const fetchStarred = (login, nextPageUrl) => ({
login,
[CALL_API]: {
- types: [ STARRED_REQUEST, STARRED_SUCCESS, STARRED_FAILURE ],
+ types: [STARRED_REQUEST, STARRED_SUCCESS, STARRED_FAILURE],
endpoint: nextPageUrl,
schema: Schemas.REPO_ARRAY
}
@@ -69,10 +73,8 @@ const fetchStarred = (login, nextPageUrl) => ({
// Bails out if page is cached and user didn't specifically request next page.
// Relies on Redux Thunk middleware.
export const loadStarred = (login, nextPage) => (dispatch, getState) => {
- const {
- nextPageUrl = `users/${login}/starred`,
- pageCount = 0
- } = getState().pagination.starredByUser[login] || {}
+ const { nextPageUrl = `users/${login}/starred`, pageCount = 0 } =
+ getState().pagination.starredByUser[login] || {}
if (pageCount > 0 && !nextPage) {
return null
@@ -90,7 +92,7 @@ export const STARGAZERS_FAILURE = 'STARGAZERS_FAILURE'
const fetchStargazers = (fullName, nextPageUrl) => ({
fullName,
[CALL_API]: {
- types: [ STARGAZERS_REQUEST, STARGAZERS_SUCCESS, STARGAZERS_FAILURE ],
+ types: [STARGAZERS_REQUEST, STARGAZERS_SUCCESS, STARGAZERS_FAILURE],
endpoint: nextPageUrl,
schema: Schemas.USER_ARRAY
}
@@ -100,10 +102,8 @@ const fetchStargazers = (fullName, nextPageUrl) => ({
// Bails out if page is cached and user didn't specifically request next page.
// Relies on Redux Thunk middleware.
export const loadStargazers = (fullName, nextPage) => (dispatch, getState) => {
- const {
- nextPageUrl = `repos/${fullName}/stargazers`,
- pageCount = 0
- } = getState().pagination.stargazersByRepo[fullName] || {}
+ const { nextPageUrl = `repos/${fullName}/stargazers`, pageCount = 0 } =
+ getState().pagination.stargazersByRepo[fullName] || {}
if (pageCount > 0 && !nextPage) {
return null
@@ -116,5 +116,5 @@ export const RESET_ERROR_MESSAGE = 'RESET_ERROR_MESSAGE'
// Resets the currently visible error message.
export const resetErrorMessage = () => ({
- type: RESET_ERROR_MESSAGE
+ type: RESET_ERROR_MESSAGE
})
diff --git a/examples/real-world/src/components/Explore.js b/examples/real-world/src/components/Explore.js
index 56168bc5ee1..8f511f16600 100644
--- a/examples/real-world/src/components/Explore.js
+++ b/examples/real-world/src/components/Explore.js
@@ -21,14 +21,14 @@ export default class Explore extends Component {
return this.input.value
}
- setInputValue = (val) => {
+ setInputValue = val => {
// Generally mutating DOM is a bad idea in React components,
// but doing this for a single uncontrolled field is less fuss
// than making it controlled and maintaining a state for it.
this.input.value = val
}
- handleKeyUp = (e) => {
+ handleKeyUp = e => {
if (e.keyCode === 13) {
this.handleGoClick()
}
@@ -42,19 +42,21 @@ export default class Explore extends Component {
return (
Type a username or repo full name and hit 'Go':
-
this.input = input}
- defaultValue={this.props.value}
- onKeyUp={this.handleKeyUp} />
-
+
(this.input = input)}
+ defaultValue={this.props.value}
+ onKeyUp={this.handleKeyUp}
+ />
+
- Code on Github.
-
-
- Move the DevTools with Ctrl+W or hide them with Ctrl+H.
+ Code on{' '}
+
+ Github
+
+ .
+
Move the DevTools with Ctrl+W or hide them with Ctrl+H.
)
}
diff --git a/examples/real-world/src/components/List.js b/examples/real-world/src/components/List.js
index 2e4e85ee0a0..e52f5557f6e 100644
--- a/examples/real-world/src/components/List.js
+++ b/examples/real-world/src/components/List.js
@@ -22,9 +22,11 @@ export default class List extends Component {
renderLoadMore() {
const { isFetching, onLoadMoreClick } = this.props
return (
-
)
-const mapStateToProps = (state) => ({
+const mapStateToProps = state => ({
canUndo: state.todos.past.length > 0,
canRedo: state.todos.future.length > 0
})
-const mapDispatchToProps = ({
+const mapDispatchToProps = {
onUndo: UndoActionCreators.undo,
onRedo: UndoActionCreators.redo
-})
+}
-UndoRedo = connect(
- mapStateToProps,
- mapDispatchToProps
-)(UndoRedo)
+UndoRedo = connect(mapStateToProps, mapDispatchToProps)(UndoRedo)
export default UndoRedo
diff --git a/examples/todos-with-undo/src/containers/VisibleTodoList.js b/examples/todos-with-undo/src/containers/VisibleTodoList.js
index 8a12dbefd1d..ff88d8ccd48 100644
--- a/examples/todos-with-undo/src/containers/VisibleTodoList.js
+++ b/examples/todos-with-undo/src/containers/VisibleTodoList.js
@@ -15,17 +15,14 @@ const getVisibleTodos = (todos, filter) => {
}
}
-const mapStateToProps = (state) => ({
+const mapStateToProps = state => ({
todos: getVisibleTodos(state.todos.present, state.visibilityFilter)
})
-const mapDispatchToProps = ({
+const mapDispatchToProps = {
onTodoClick: toggleTodo
-})
+}
-const VisibleTodoList = connect(
- mapStateToProps,
- mapDispatchToProps
-)(TodoList)
+const VisibleTodoList = connect(mapStateToProps, mapDispatchToProps)(TodoList)
export default VisibleTodoList
diff --git a/examples/todos-with-undo/src/reducers/todos.js b/examples/todos-with-undo/src/reducers/todos.js
index 9df2d57a9cc..b6022b4d297 100644
--- a/examples/todos-with-undo/src/reducers/todos.js
+++ b/examples/todos-with-undo/src/reducers/todos.js
@@ -25,14 +25,9 @@ const todo = (state, action) => {
const todos = (state = [], action) => {
switch (action.type) {
case 'ADD_TODO':
- return [
- ...state,
- todo(undefined, action)
- ]
+ return [...state, todo(undefined, action)]
case 'TOGGLE_TODO':
- return state.map(t =>
- todo(t, action)
- )
+ return state.map(t => todo(t, action))
default:
return state
}
diff --git a/examples/todos/public/index.html b/examples/todos/public/index.html
index 2e474bce12d..8a26bc76d7f 100644
--- a/examples/todos/public/index.html
+++ b/examples/todos/public/index.html
@@ -1,8 +1,8 @@
-
+
-
-
+
+
Redux Todos Example
diff --git a/examples/todos/src/components/Footer.js b/examples/todos/src/components/Footer.js
index 60198e84b47..1feb0f403c0 100644
--- a/examples/todos/src/components/Footer.js
+++ b/examples/todos/src/components/Footer.js
@@ -5,15 +5,9 @@ import { VisibilityFilters } from '../actions'
const Footer = () => (
Show:
-
- All
-
-
- Active
-
-
- Completed
-
+ All
+ Active
+ Completed
)
diff --git a/examples/todos/src/components/Link.js b/examples/todos/src/components/Link.js
index 9ae6af46283..2395bf640e2 100644
--- a/examples/todos/src/components/Link.js
+++ b/examples/todos/src/components/Link.js
@@ -2,15 +2,15 @@ import React from 'react'
import PropTypes from 'prop-types'
const Link = ({ active, children, onClick }) => (
-
- {children}
-
+
+ {children}
+
)
Link.propTypes = {
diff --git a/examples/todos/src/components/TodoList.js b/examples/todos/src/components/TodoList.js
index 7591db6b61e..082620adb73 100644
--- a/examples/todos/src/components/TodoList.js
+++ b/examples/todos/src/components/TodoList.js
@@ -4,22 +4,20 @@ import Todo from './Todo'
const TodoList = ({ todos, toggleTodo }) => (
- {todos.map(todo =>
- toggleTodo(todo.id)}
- />
- )}
+ {todos.map(todo => (
+ toggleTodo(todo.id)} />
+ ))}
)
TodoList.propTypes = {
- todos: PropTypes.arrayOf(PropTypes.shape({
- id: PropTypes.number.isRequired,
- completed: PropTypes.bool.isRequired,
- text: PropTypes.string.isRequired
- }).isRequired).isRequired,
+ todos: PropTypes.arrayOf(
+ PropTypes.shape({
+ id: PropTypes.number.isRequired,
+ completed: PropTypes.bool.isRequired,
+ text: PropTypes.string.isRequired
+ }).isRequired
+ ).isRequired,
toggleTodo: PropTypes.func.isRequired
}
diff --git a/examples/todos/src/containers/AddTodo.js b/examples/todos/src/containers/AddTodo.js
index 63cfc76daab..fdbdf30388d 100644
--- a/examples/todos/src/containers/AddTodo.js
+++ b/examples/todos/src/containers/AddTodo.js
@@ -7,18 +7,18 @@ const AddTodo = ({ dispatch }) => {
return (
-
)
diff --git a/examples/todos/src/containers/FilterLink.js b/examples/todos/src/containers/FilterLink.js
index a733d21be0c..e930c59fb0b 100644
--- a/examples/todos/src/containers/FilterLink.js
+++ b/examples/todos/src/containers/FilterLink.js
@@ -10,7 +10,4 @@ const mapDispatchToProps = (dispatch, ownProps) => ({
onClick: () => dispatch(setVisibilityFilter(ownProps.filter))
})
-export default connect(
- mapStateToProps,
- mapDispatchToProps
-)(Link)
+export default connect(mapStateToProps, mapDispatchToProps)(Link)
diff --git a/examples/todos/src/containers/VisibleTodoList.js b/examples/todos/src/containers/VisibleTodoList.js
index 1c69a9ec198..b13e90617cd 100644
--- a/examples/todos/src/containers/VisibleTodoList.js
+++ b/examples/todos/src/containers/VisibleTodoList.js
@@ -24,7 +24,4 @@ const mapDispatchToProps = dispatch => ({
toggleTodo: id => dispatch(toggleTodo(id))
})
-export default connect(
- mapStateToProps,
- mapDispatchToProps
-)(TodoList)
+export default connect(mapStateToProps, mapDispatchToProps)(TodoList)
diff --git a/examples/todos/src/reducers/todos.js b/examples/todos/src/reducers/todos.js
index fc6ed32d88d..bb4befe0b42 100644
--- a/examples/todos/src/reducers/todos.js
+++ b/examples/todos/src/reducers/todos.js
@@ -11,9 +11,7 @@ const todos = (state = [], action) => {
]
case 'TOGGLE_TODO':
return state.map(todo =>
- (todo.id === action.id)
- ? {...todo, completed: !todo.completed}
- : todo
+ todo.id === action.id ? { ...todo, completed: !todo.completed } : todo
)
default:
return state
diff --git a/examples/todos/src/reducers/todos.spec.js b/examples/todos/src/reducers/todos.spec.js
index 88eca35d78b..1cec2bc7179 100644
--- a/examples/todos/src/reducers/todos.spec.js
+++ b/examples/todos/src/reducers/todos.spec.js
@@ -2,9 +2,7 @@ import todos from './todos'
describe('todos reducer', () => {
it('should handle initial state', () => {
- expect(
- todos(undefined, {})
- ).toEqual([])
+ expect(todos(undefined, {})).toEqual([])
})
it('should handle ADD_TODO', () => {
@@ -23,23 +21,27 @@ describe('todos reducer', () => {
])
expect(
- todos([
+ todos(
+ [
+ {
+ text: 'Run the tests',
+ completed: false,
+ id: 0
+ }
+ ],
{
- text: 'Run the tests',
- completed: false,
- id: 0
+ type: 'ADD_TODO',
+ text: 'Use Redux',
+ id: 1
}
- ], {
- type: 'ADD_TODO',
- text: 'Use Redux',
- id: 1
- })
+ )
).toEqual([
{
text: 'Run the tests',
completed: false,
id: 0
- }, {
+ },
+ {
text: 'Use Redux',
completed: false,
id: 1
@@ -47,31 +49,37 @@ describe('todos reducer', () => {
])
expect(
- todos([
+ todos(
+ [
+ {
+ text: 'Run the tests',
+ completed: false,
+ id: 0
+ },
+ {
+ text: 'Use Redux',
+ completed: false,
+ id: 1
+ }
+ ],
{
- text: 'Run the tests',
- completed: false,
- id: 0
- }, {
- text: 'Use Redux',
- completed: false,
- id: 1
+ type: 'ADD_TODO',
+ text: 'Fix the tests',
+ id: 2
}
- ], {
- type: 'ADD_TODO',
- text: 'Fix the tests',
- id: 2
- })
+ )
).toEqual([
{
text: 'Run the tests',
completed: false,
id: 0
- }, {
+ },
+ {
text: 'Use Redux',
completed: false,
id: 1
- }, {
+ },
+ {
text: 'Fix the tests',
completed: false,
id: 2
@@ -81,31 +89,35 @@ describe('todos reducer', () => {
it('should handle TOGGLE_TODO', () => {
expect(
- todos([
+ todos(
+ [
+ {
+ text: 'Run the tests',
+ completed: false,
+ id: 1
+ },
+ {
+ text: 'Use Redux',
+ completed: false,
+ id: 0
+ }
+ ],
{
- text: 'Run the tests',
- completed: false,
+ type: 'TOGGLE_TODO',
id: 1
- }, {
- text: 'Use Redux',
- completed: false,
- id: 0
}
- ], {
- type: 'TOGGLE_TODO',
- id: 1
- })
+ )
).toEqual([
{
text: 'Run the tests',
completed: true,
id: 1
- }, {
+ },
+ {
text: 'Use Redux',
completed: false,
id: 0
}
])
})
-
})
diff --git a/examples/tree-view/public/index.html b/examples/tree-view/public/index.html
index 7154a496d61..a925797f25a 100644
--- a/examples/tree-view/public/index.html
+++ b/examples/tree-view/public/index.html
@@ -1,8 +1,8 @@
-
+
-
-
+
+
Redux Tree View Example
diff --git a/examples/tree-view/src/actions/index.js b/examples/tree-view/src/actions/index.js
index ceead7e6044..759ffe1bfeb 100644
--- a/examples/tree-view/src/actions/index.js
+++ b/examples/tree-view/src/actions/index.js
@@ -4,7 +4,7 @@ export const DELETE_NODE = 'DELETE_NODE'
export const ADD_CHILD = 'ADD_CHILD'
export const REMOVE_CHILD = 'REMOVE_CHILD'
-export const increment = (nodeId) => ({
+export const increment = nodeId => ({
type: INCREMENT,
nodeId
})
@@ -15,7 +15,7 @@ export const createNode = () => ({
nodeId: `new_${nextId++}`
})
-export const deleteNode = (nodeId) => ({
+export const deleteNode = nodeId => ({
type: DELETE_NODE,
nodeId
})
diff --git a/examples/tree-view/src/containers/Node.js b/examples/tree-view/src/containers/Node.js
index 6511e22d61d..80d6324f03d 100644
--- a/examples/tree-view/src/containers/Node.js
+++ b/examples/tree-view/src/containers/Node.js
@@ -38,22 +38,22 @@ export class Node extends Component {
const { counter, parentId, childIds } = this.props
return (
- Counter: {counter}
- {' '}
-
- +
-
- {' '}
- {typeof parentId !== 'undefined' &&
-
+ Counter: {counter}{' '}
+ +{' '}
+ {typeof parentId !== 'undefined' && (
+
×
- }
+ )}
{childIds.map(this.renderChild)}
-
-
Add child
diff --git a/examples/tree-view/src/containers/Node.spec.js b/examples/tree-view/src/containers/Node.spec.js
index 9b9948abbf5..2a325283199 100644
--- a/examples/tree-view/src/containers/Node.spec.js
+++ b/examples/tree-view/src/containers/Node.spec.js
@@ -16,13 +16,21 @@ function setup(id, counter, childIds, parentId) {
}
const component = shallow(
-
+
)
return {
component: component,
removeLink: component.findWhere(n => n.type() === 'a' && n.contains('×')),
- addLink: component.findWhere(n => n.type() === 'a' && n.contains('Add child')),
+ addLink: component.findWhere(
+ n => n.type() === 'a' && n.contains('Add child')
+ ),
button: component.find('button'),
childNodes: component.find(ConnectedNode),
actions: actions,
@@ -67,7 +75,7 @@ describe('Node component', () => {
describe('when given childIds', () => {
it('should render child nodes', () => {
- const { childNodes } = setup(1, 23, [ 2, 3 ])
+ const { childNodes } = setup(1, 23, [2, 3])
expect(childNodes.length).toEqual(2)
})
})
diff --git a/examples/tree-view/src/reducers/index.js b/examples/tree-view/src/reducers/index.js
index 0e765c57be0..87de0fcee07 100644
--- a/examples/tree-view/src/reducers/index.js
+++ b/examples/tree-view/src/reducers/index.js
@@ -1,9 +1,15 @@
-import { INCREMENT, ADD_CHILD, REMOVE_CHILD, CREATE_NODE, DELETE_NODE } from '../actions'
+import {
+ INCREMENT,
+ ADD_CHILD,
+ REMOVE_CHILD,
+ CREATE_NODE,
+ DELETE_NODE
+} from '../actions'
const childIds = (state, action) => {
switch (action.type) {
case ADD_CHILD:
- return [ ...state, action.childId ]
+ return [...state, action.childId]
case REMOVE_CHILD:
return state.filter(id => id !== action.childId)
default:
@@ -35,11 +41,11 @@ const node = (state, action) => {
}
}
-const getAllDescendantIds = (state, nodeId) => (
- state[nodeId].childIds.reduce((acc, childId) => (
- [ ...acc, childId, ...getAllDescendantIds(state, childId) ]
- ), [])
-)
+const getAllDescendantIds = (state, nodeId) =>
+ state[nodeId].childIds.reduce(
+ (acc, childId) => [...acc, childId, ...getAllDescendantIds(state, childId)],
+ []
+ )
const deleteMany = (state, ids) => {
state = { ...state }
@@ -55,7 +61,7 @@ export default (state = {}, action) => {
if (action.type === DELETE_NODE) {
const descendantIds = getAllDescendantIds(state, nodeId)
- return deleteMany(state, [ nodeId, ...descendantIds ])
+ return deleteMany(state, [nodeId, ...descendantIds])
}
return {
diff --git a/examples/tree-view/src/reducers/index.spec.js b/examples/tree-view/src/reducers/index.spec.js
index 5fbd5b5d0f8..53975d0ca37 100644
--- a/examples/tree-view/src/reducers/index.spec.js
+++ b/examples/tree-view/src/reducers/index.spec.js
@@ -1,6 +1,12 @@
import deepFreeze from 'deep-freeze'
import reducer from './index'
-import { increment, createNode, deleteNode, addChild, removeChild } from '../actions'
+import {
+ increment,
+ createNode,
+ deleteNode,
+ addChild,
+ removeChild
+} from '../actions'
describe('reducer', () => {
it('should provide the initial state', () => {
@@ -9,7 +15,7 @@ describe('reducer', () => {
it('should handle INCREMENT action', () => {
const stateBefore = {
- 'node_0': {
+ node_0: {
id: 'node_0',
counter: 0,
childIds: []
@@ -17,7 +23,7 @@ describe('reducer', () => {
}
const action = increment('node_0')
const stateAfter = {
- 'node_0': {
+ node_0: {
id: 'node_0',
counter: 1,
childIds: []
@@ -49,27 +55,27 @@ describe('reducer', () => {
it('should handle DELETE_NODE action', () => {
const stateBefore = {
- 'node_0': {
+ node_0: {
id: 'node_0',
counter: 0,
- childIds: [ 'node_1' ]
+ childIds: ['node_1']
},
- 'node_1': {
+ node_1: {
id: 'node_1',
counter: 0,
childIds: []
},
- 'node_2': {
+ node_2: {
id: 'node_2',
counter: 0,
- childIds: [ 'node_3', 'node_4' ]
+ childIds: ['node_3', 'node_4']
},
- 'node_3': {
+ node_3: {
id: 'node_3',
counter: 0,
childIds: []
},
- 'node_4': {
+ node_4: {
id: 'node_4',
counter: 0,
childIds: []
@@ -77,12 +83,12 @@ describe('reducer', () => {
}
const action = deleteNode('node_2')
const stateAfter = {
- 'node_0': {
+ node_0: {
id: 'node_0',
counter: 0,
- childIds: [ 'node_1' ]
+ childIds: ['node_1']
},
- 'node_1': {
+ node_1: {
id: 'node_1',
counter: 0,
childIds: []
@@ -97,12 +103,12 @@ describe('reducer', () => {
it('should handle ADD_CHILD action', () => {
const stateBefore = {
- 'node_0': {
+ node_0: {
id: 'node_0',
counter: 0,
childIds: []
},
- 'node_1': {
+ node_1: {
id: 'node_1',
counter: 0,
childIds: []
@@ -110,12 +116,12 @@ describe('reducer', () => {
}
const action = addChild('node_0', 'node_1')
const stateAfter = {
- 'node_0': {
+ node_0: {
id: 'node_0',
counter: 0,
- childIds: [ 'node_1' ]
+ childIds: ['node_1']
},
- 'node_1': {
+ node_1: {
id: 'node_1',
counter: 0,
childIds: []
@@ -130,12 +136,12 @@ describe('reducer', () => {
it('should handle REMOVE_CHILD action', () => {
const stateBefore = {
- 'node_0': {
+ node_0: {
id: 'node_0',
counter: 0,
- childIds: [ 'node_1' ]
+ childIds: ['node_1']
},
- 'node_1': {
+ node_1: {
id: 'node_1',
counter: 0,
childIds: []
@@ -143,12 +149,12 @@ describe('reducer', () => {
}
const action = removeChild('node_0', 'node_1')
const stateAfter = {
- 'node_0': {
+ node_0: {
id: 'node_0',
counter: 0,
childIds: []
},
- 'node_1': {
+ node_1: {
id: 'node_1',
counter: 0,
childIds: []
diff --git a/examples/universal/.babelrc b/examples/universal/.babelrc
index dd87fb51360..86c445f5451 100644
--- a/examples/universal/.babelrc
+++ b/examples/universal/.babelrc
@@ -1,3 +1,3 @@
{
- presets: ["es2015", "react"]
-}
\ No newline at end of file
+ "presets": ["es2015", "react"]
+}
diff --git a/examples/universal/client/index.js b/examples/universal/client/index.js
index 7e5b025b70b..4060c1f5357 100644
--- a/examples/universal/client/index.js
+++ b/examples/universal/client/index.js
@@ -11,7 +11,7 @@ const rootElement = document.getElementById('app')
render(
-
+
,
rootElement
)
diff --git a/examples/universal/common/actions/index.js b/examples/universal/common/actions/index.js
index de1ec95490d..295914e8ac2 100644
--- a/examples/universal/common/actions/index.js
+++ b/examples/universal/common/actions/index.js
@@ -2,7 +2,7 @@ export const SET_COUNTER = 'SET_COUNTER'
export const INCREMENT_COUNTER = 'INCREMENT_COUNTER'
export const DECREMENT_COUNTER = 'DECREMENT_COUNTER'
-export const set = (value) => ({
+export const set = value => ({
type: SET_COUNTER,
payload: value
})
@@ -25,8 +25,10 @@ export const incrementIfOdd = () => (dispatch, getState) => {
dispatch(increment())
}
-export const incrementAsync = (delay = 1000) => dispatch => {
- setTimeout(() => {
- dispatch(increment())
- }, delay)
-}
+export const incrementAsync =
+ (delay = 1000) =>
+ dispatch => {
+ setTimeout(() => {
+ dispatch(increment())
+ }, delay)
+ }
diff --git a/examples/universal/common/api/counter.js b/examples/universal/common/api/counter.js
index 18dd526b956..6de7b3d9eb6 100644
--- a/examples/universal/common/api/counter.js
+++ b/examples/universal/common/api/counter.js
@@ -1,8 +1,6 @@
-const getRandomInt = (min, max) => (
- Math.floor(Math.random() * (max - min)) + min
-)
+const getRandomInt = (min, max) => Math.floor(Math.random() * (max - min)) + min
-export const fetchCounter = (callback) => {
+export const fetchCounter = callback => {
// Rather than immediately returning, we delay our code with a timeout to simulate asynchronous behavior
setTimeout(() => {
callback(getRandomInt(1, 100))
diff --git a/examples/universal/common/components/Counter.js b/examples/universal/common/components/Counter.js
index c26a5bb4f86..002391e9594 100644
--- a/examples/universal/common/components/Counter.js
+++ b/examples/universal/common/components/Counter.js
@@ -1,16 +1,17 @@
import React from 'react'
import PropTypes from 'prop-types'
-const Counter = ({increment, incrementIfOdd, incrementAsync, decrement, counter}) => (
+const Counter = ({
+ increment,
+ incrementIfOdd,
+ incrementAsync,
+ decrement,
+ counter
+}) => (
- Clicked: {counter} times
- {' '}
- +
- {' '}
- -
- {' '}
- Increment if odd
- {' '}
+ Clicked: {counter} times +{' '}
+ -{' '}
+ Increment if odd{' '}
incrementAsync()}>Increment async
)
diff --git a/examples/universal/common/containers/App.js b/examples/universal/common/containers/App.js
index 202c2148f07..d9718f4dfd8 100644
--- a/examples/universal/common/containers/App.js
+++ b/examples/universal/common/containers/App.js
@@ -3,11 +3,11 @@ import { connect } from 'react-redux'
import Counter from '../components/Counter'
import * as CounterActions from '../actions'
-const mapStateToProps = (state) => ({
+const mapStateToProps = state => ({
counter: state.counter
})
-const mapDispatchToProps = (dispatch) => {
+const mapDispatchToProps = dispatch => {
return bindActionCreators(CounterActions, dispatch)
}
diff --git a/examples/universal/common/store/configureStore.js b/examples/universal/common/store/configureStore.js
index 8ba6c576e08..c2c9e5738a9 100644
--- a/examples/universal/common/store/configureStore.js
+++ b/examples/universal/common/store/configureStore.js
@@ -2,12 +2,8 @@ import { createStore, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
import rootReducer from '../reducers'
-const configureStore = (preloadedState) => {
- const store = createStore(
- rootReducer,
- preloadedState,
- applyMiddleware(thunk)
- )
+const configureStore = preloadedState => {
+ const store = createStore(rootReducer, preloadedState, applyMiddleware(thunk))
if (module.hot) {
// Enable Webpack hot module replacement for reducers
diff --git a/examples/universal/server/server.js b/examples/universal/server/server.js
index c8fb073b6dc..ef9d8ede468 100644
--- a/examples/universal/server/server.js
+++ b/examples/universal/server/server.js
@@ -21,7 +21,12 @@ const port = 3000
// Use this middleware to set up hot module reloading via webpack.
const compiler = webpack(webpackConfig)
-app.use(webpackDevMiddleware(compiler, { noInfo: true, publicPath: webpackConfig.output.publicPath }))
+app.use(
+ webpackDevMiddleware(compiler, {
+ noInfo: true,
+ publicPath: webpackConfig.output.publicPath
+ })
+)
app.use(webpackHotMiddleware(compiler))
const handleRender = (req, res) => {
@@ -65,7 +70,10 @@ const renderFullPage = (html, preloadedState) => {
${html}
@@ -73,10 +81,12 @@ const renderFullPage = (html, preloadedState) => {
`
}
-app.listen(port, (error) => {
+app.listen(port, error => {
if (error) {
console.error(error)
} else {
- console.info(`==> 🌎 Listening on port ${port}. Open up http://localhost:${port}/ in your browser.`)
+ console.info(
+ `==> 🌎 Listening on port ${port}. Open up http://localhost:${port}/ in your browser.`
+ )
}
})
diff --git a/examples/universal/webpack.config.js b/examples/universal/webpack.config.js
index e1257306170..be2f06fef78 100644
--- a/examples/universal/webpack.config.js
+++ b/examples/universal/webpack.config.js
@@ -4,18 +4,13 @@ var webpack = require('webpack')
module.exports = {
mode: process.env.NODE_ENV || 'development',
devtool: 'inline-source-map',
- entry: [
- 'webpack-hot-middleware/client',
- './client/index.js'
- ],
+ entry: ['webpack-hot-middleware/client', './client/index.js'],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/'
},
- plugins: [
- new webpack.HotModuleReplacementPlugin()
- ],
+ plugins: [new webpack.HotModuleReplacementPlugin()],
module: {
rules: [
{
@@ -24,7 +19,7 @@ module.exports = {
exclude: /node_modules/,
include: __dirname,
options: {
- presets: [ 'react-hmre' ]
+ presets: ['react-hmre']
}
}
]
diff --git a/src/bindActionCreators.ts b/src/bindActionCreators.ts
index 1946add8ac8..b9689c25484 100644
--- a/src/bindActionCreators.ts
+++ b/src/bindActionCreators.ts
@@ -1,5 +1,9 @@
import type { Dispatch } from './types/store'
-import type { ActionCreator, ActionCreatorsMapObject, Action } from './types/actions'
+import type {
+ ActionCreator,
+ ActionCreatorsMapObject,
+ Action
+} from './types/actions'
import { kindOf } from './utils/kindOf'
function bindActionCreator(