Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/function based components #23

Conversation

zyphlar
Copy link
Member

@zyphlar zyphlar commented Apr 29, 2023

Replaces #10

✏️ Changes

  1. Creates event edit functionality
  2. Totally changes around all the shit

🔧 Steps to test

  1. Spin it all up and ensure fixtures are created
  2. View an event
  3. Go to its /edit URL
  4. Make changes and hit save

The redux app state has several branches, including the "events" branch.
Previously, this "events" branch was provided as props to the Events component through the the `connect` call and its `mapStateToProps` argument.
Another prop provided by the `connect` call was the `getAll()` prop.
This prop didn't rely on a branch of the app state; instead it was set up to dispatch actions which were then handled by the redux action handlers.

We still select the same "events" branch of the app state, but do so within the component itself through the `useSelector` call, which receives the entire app state, and slices-off and returns the "events" branch.

We still dispatch the same "getAll" action when the component mounts, but do so through the `useDispatch` call, which returns the redux dispatcher directly.

Instead of using the "componentDidMount" Component lifecycle hook, we use the `useEffect` hook to run the hook once, when the component is first rendered.

The second argument to "connect" was a mapping of action creators to prop names. Within that call, redux wrapped each of these action creators with the equivalent of `dispatch(…)`.
Now, we have access to `dispatch` directly, through the `useDispatch` hook.
@zyphlar zyphlar merged commit 8cfe47d into heatsynclabs:develop Apr 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants