React.js API ConsumerĀ šŸš€

Obada Qawwas
in - React

This project was bootstrapped withĀ Create React App.
The project includes extra packages and improved file structure.

Dependencies that were added to CRA šŸ‘·šŸ¼ā€ā™€ļø

  • axios
  • redux
  • react-redux
  • redux-saga
  • redux-devtools-extension
  • react-router-dom
  • react-router-redux

Public APIĀ šŸ–¼

This project gets its data from Artic EDU (The Art Institute of Chicago) for demo purposes, it’s an open API and doesn’t require a key. View its documentation atĀ Art Institute of Chicago APIĀ More Public API’s can be foundĀ here.

FeaturesĀ šŸ¦ø

  • Typescript – Superset of JavaScript which primarily provides optional static typing, classes and interfaces.
  • Redux – A predictable state container for JavaScript apps.
  • Sagas – An intuitive Redux side effect manager. Easy to manage, easy to test, and executes efficiently.
  • Sass/Scss – CSS preprocessor, which adds special features such as variables, nested rules and mixins (sometimes referred to as syntactic sugar) into regular CSS.
  • BEM – Block Element Modifier is a methodology that helps you to create reusable components and code sharing in front-end development.
  • ESLint – The pluggable linting utility.
  • Jest – Javascript testing framework, created by developers who created React.

RoutesĀ šŸ›£

Project’s main modules

  • Home page

    Shows the fetched posts, fetched posts are limited to 20, pagination is should be implemented to fetch more, also, images should be lazy-loaded.

  • Single post page.

    Post image should be lazy-loaded.

  • Error 404

Folders and files structureĀ šŸ—ŗ

- src
    - components // reusable react components
        - CircularProgress
        - Header
        - PostItem

        // Each component has the following structure:
        - * ComponentName
            - ComponentName.module.scss
            - ComponentName.test.tsx
            - ComponentName.tsx
            - index.ts

    - hocs
        - withErrorHandler.tsx

    - lib // helpers
        - scripts
            - apis.ts // contains all the API calls
            - axios.ts
            - test-utils.js
            - utils.ts
        - styles
            - abstracts
                - _mixins.scss
                - _variables.scss
            - main.scss

    - routes // main modules, which are react components and might have a redux store
        // It's not named containers because we might have containers that are not pages/routes, so a new folder called containers will be added for them.
        // Each route has the same structure as components but some routes might have a store folder that contains all Redux's related files.
        - ErrorPage
        - HomePage
        - SinglePost
        - * RouteName
            - store
                - actions.spec.ts
                - actions.ts
                - connector.ts // exports Redux's connect HOC
                - constants.ts
                - reducers.spec.ts
                - reducers.ts
                - sagas.spec.ts
                - sagas.ts
            - RouteName.module.scss
            - RouteName.test.tsx
            - RouteName.tsx
            - index.ts
        - index.tsx // contains the main React Router DOM routes, new routes must be added here

    - App.test.tsx
    - App.tsx
    - config.ts // App's config, now it only contains API_URL and POSTS_LIMIT
    - global-reducers.ts // state's reducers, add new reducers here
    - global-sagas.ts // connect routes sagas here
    - index.tsx
    - store.ts // Redux store implementation

How to launch the projectĀ šŸ

InstallĀ Node.jsĀ and then open the Terminal/CMD and navigate to the project’s folder. Run the following command:

npm insatll

Development evnironment

npm start

Runs the app in the development mode.
OpenĀ http://localhost:3000Ā to view it in the browser.

The page will reload if you make edits.
You will also see any lint errors in the console.

Production build

npm run build

Builds the app for production to theĀ buildĀ folder.
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.
Your app is ready to be deployed!

See the section aboutĀ deploymentĀ for more information.

Testing

npm run test

Launches the test runner in the interactive watch mode.
See the section aboutĀ running testsĀ for more information.

npm run eject

Note: this is a one-way operation. Once youĀ eject, you canā€™t go back!

If you arenā€™t satisfied with the build tool and configuration choices, you canĀ ejectĀ at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands exceptĀ ejectĀ will still work, but they will point to the copied scripts so you can tweak them. At this point youā€™re on your own.

You donā€™t have to ever useĀ eject. The curated feature set is suitable for small and middle deployments, and you shouldnā€™t feel obligated to use this feature. However we understand that this tool wouldnā€™t be useful if you couldnā€™t customize it when you are ready for it.

Learn More

You can learn more in theĀ Create React App documentation.

To learn React, check out theĀ React documentation.

Stay safe šŸ˜·

Please enable Javascript in order to post comments.