This project is designed to help practice using redux actions to control data that is changed through user interactions. On the left hand side of the page is a collection of different inputs that are available on a web page. When the user interacts with the input it will change some data that should update the right hand side of the page. All you need to do is build the redux containers such that it will connect redux actions and data to the components. You do not need to alter the existing components themselves to complete this project.
- fork
- clone
- npm install
- npm start
Redux actions, reducers, store & containers. mapStateToProps and mapDispatchToProps.
- Use the inputs and buttons on the left side of the page to modify the UI on the right side of the page.
- Every component inside
App.js
has been replaced by a container.
- Clicking on the button
Increase Counter By One
should increment theCounter
by 1 - Clicking on the button
Decrease Counter By One
should decrease theCounter
by 1 - Inputting text inside the
Enter Special Text
field display a value next toSpecial Text
- Inputting text inside the
name
field should filter users by first name - Selecting a sort option inside
Sort Users
should sort users by first or last name - Clicking on the button
Add User
should add a single user to the user list - Clicking on the button
Remove User
should remove a single user from the user list - Selecting a city in the
Select Current City
dropdown should display a value next toCurrent City
- Inputting a number inside the
Temp
field should change the tempature assign to the donut chart - Inputting a image url inside the
url
field should display a image underImage Preview
- Moving the slider should change the size of the image displayed under
Image Preview
- Clicking
Display Modal
should display the modal nested inside theModal
component - Do one thing at a time, save and refresh to check for errors
- Create the desired action
- Create or modify a reducer to handle the action
- Create or modify a container to map the action to the desired component prop function
- Create or modify a container to map the reducer state to the desired component prop
- Replace components in
App.js
with appropriate containers
- Locate the actions file in actions/index.js
- Create a action for each piece of state.
- Each action should return a
type
andvalue
property
- Locate the reducers file in reducers/index.js
- Create or modify reducer for each piece of state listed below.
- currentCount,
- currentCity,
- searchText,
- currentTemp,
- displayModal,
- imageUrl,
- currentUserSort,
- imageScale,
- users,
- specialText
- Reducers take 2 parameters:
state
, andaction
- Reducers should return a state value based on action type
- Reducers should return a default state value
- Reducers should be combined and exported
- Leave the components alone and create containers to interact with your new Redux logic.
- In the
containers
folder, create a container file for the following components:- SpecialText.js
- map a prop called
text
to the statespecialText
- map a prop called
- Users.js
- map a prop called
users
to the stateusers
- map a prop called
firstNameFilter
to the statesearchText
- map a prop called
sortOn
to the statecurrentUserSort
- map a prop called
- Counter.js
- map a prop called
count
to the statecurrentCount
- map a prop called
- CurrentCity.js
- map a prop called
text
to the statecurrentCity
- map a prop called
- Thermostat.js
- map a prop called
temp
to the statecurrentTemp
- map a prop called
- ImagePreview.js
- map a prop called
URL
to the stateimagrUrl
- map a prop called
scale
to the stateimageScale
- map a prop called
- Modal.js
- map a prop called
displayModal
to the statedisplayModal
- map a prop called
- UserButtons.js
- map prop
add
toaddUser
action - map prop
remove
toremoveUser
action
- map prop
- CityDropDown.js
- map prop
set
tosetCurrentCity
action
- map prop
- CounterButton.js
- map prop
increase
toincreaseCounter
action - map prop
decrease
todecreaseCounter
action
- map prop
- SearchTextBox.js
- map prop
set
tosetSearchText
action
- map prop
- ChangeTemperature.js
- map prop
set
to actionsetTemp
action
- map prop
- ImageUrlTextBox.js
- map prop
set
tosetImageUrl
action
- map prop
- SortUsers.js
- map prop
set
tosetCurrentUserSort
action
- map prop
- ScaleImage.js
- map prop
set
to actionsetImageScale
action
- map prop
- ShowModal.js
- map prop
toggleModal
totoggleModal
action
- map prop
- Modal.js
- map prop
toggleModal
totoggleModal
action
- map prop
- SpecialText.js
- Import the appropriate component and actions into the container file
- Create a mapStateToProps function to map props to the appropriate state
- Create a mapDispatchToProps object to map props to the appropriate actions
- Export the container using the react-redux
connect
function
- Modify App.js to use the containers you created instead of components
Currently, the users are hard coded in the state.js file. Change that data so it is coming from an api. https://jsonplaceholder.typicode.com/users
- Things to consider:
- We should know how to make a fetch call by now. Where does the fetch call go?
- What do you do with the data when the fetch call is complete? Not setState.
- Is there an action message that could represent that the redux store needs to be updated with the list of users you just fetched from the api.
- Does any reducer need to be aware of this message?