Git Product home page Git Product logo

redux-photo-app's Introduction

Mini Project: Photo App

Setup environment

Github Project: https://github.com/paulnguyen-mn/redux-photo-app

1. Setup ReactJS App via Create React App

Link: https://create-react-app.dev/docs/getting-started/

2. Add SCSS support

npm i --save-dev node-sass

3. Add react router

npm i --save react-router-dom

4. Add UI lib

npm i --save reactstrap

Tổ chức folder

src
|__ assets
|  |__ images
|  |__ styles (global styles) 
|
|__ components (shared components)
|
|__ features
  |__ Photo
    |__ components
    |  |__ PhotoList
    |  |__ PhotoCard
    |  |__ PhotoForm
    |
    |__ pages
    |  |__ MainPage
    |  |__ AddEditPage
    |__ photoSlice.js
    |__ index.js

Tổ chức routing

  • Sử dụng kĩ thuật lazy load components.
  • Load theo features.
// App.js
function App() {
  return (
    <BrowserRouter>
      <Switch>
        <Route path="/photos" component={Photo} />
        <Route path="/user" component={User} />
        <Route component={NotFound} />
      </Switch>
    </BrowserRouter>
  )
}

Custom Field

  • Cầu nối giữa UI control và Formik.
  • UI control là một controlled component với props:
    • name: tên xác định control
    • value: giá trị của control
    • onChange: trigger hàm này với giá trị mới khi có thay đổi
    • onBlur: xác định khi nào thì control này bị touched
function InputField(props) {
  const {
    field,
    type, label, placeholder, disabled,
  } = props;
  const { name } = field;

  return (
    <FormGroup>
      {label && <Label for={name}>{label}</Label>}

      <Input
        id={name}
        {...field}

        type={type}
        disabled={disabled}
        placeholder={placeholder}
      />
    </FormGroup>
  );
}

Random Photo control

RandomPhoto Props

  • name
  • imageUrl
  • onImageUrlChange
  • onRandomButtonBlur

RandomPhotoField

Formik

Yup

redux-photo-app's People

Contributors

paulnguyen-mn avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.