Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 5474

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 27, 20242024-11-27T09:36:06+00:00 2024-11-27T09:36:06+00:00

Rails with React/Redux

  • 61k

I created a React app that uses Redux for controlling state and learning that has not been the best road. The app is also using Ruby on Rails for a backend API store data in.
This app is a cookbook for storing recipes and being able to leave reviews as well as give it a rating to show how much you like each recipe.

React

Generating a React app is quite easy to start off with npx create-react-app and start by adding components. At first it felt a little foreign then after five minutes of using it, things started to find their way into places. Files feel more like a proper structure using the React framework with being able to target files using import React from 'react' at the top of the file. The format is used for collecting any other file that has been exported in their home file.

Rails

Setting up the Rails api was nearly just as easy with the quick command rails new CoolBackend --api using the api flag with prevent views from being generated. Also to be noted, one should not use rails scaffold as that will generate views which ultimately will not be used for this type of application, that will be handled by React.

Redux

Redux is a library that is used to control a “global” state as it were. State is normally created in a class component and is then passed down to child components. Sending state down several child components gets to be a little tedious which leaves Redux to the rescue!

Redux allows for action creators to be called on from anywhere in the React file structure and be used to track state. This functions are imported just the same as any other file would be collected.

A common action would like how I set up fetching all recipes:

const API = 'http://localhost:3000'  export const fetchRecipes = () => {   return dispatch => {     fetch(`${API}/recipes`)     .then(resp => resp.json())     .then(recipes => dispatch({        type: 'GET_RECIPES',       payload: recipes }))   } } 
Enter fullscreen mode Exit fullscreen mode

This function has the keyword dispatch and it used by redux-thunk which allows for AJAX requests to and from the API endpoint which works asynchronously.

With this functionality helps to keep state up to date with the rest of the app and keeps local state clean and more manageable.

Conclusion

My learning journey with React and Redux has been a fun one right after just becoming acquainted with JavaScript made for some confusing mistakes. One being how to update state when a new route has been met. For that componentDidMount() helps for firing off a quick redux action creator to get the list of recipes when navigating to the /recipes route.

More lifecycle methods exist along with all the React hooks I did not have time to look into look to make using React/Redux a more streamed lined affair.

railsreactreduxwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 1k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.