Giter Club home page Giter Club logo

react-projects-smilga's Introduction

04-Accordion

Idea

uidesigndaily

React Icons

react icons

npm install react-icons --save
import { FaHome } from "react-icons/fa";
const Component = () => {
  return <FaHome className="icon"></FaHome>;
};

Content

  • spread ... to child component
  • useState
  • ternary
  • show\hide short-circuit-and

05-Menu

Content

  • useState
  • filtering components
  • pattern to extract objects unique values to array.
const allCategories = ["all", ...new Set(items.map((item) => item.category))];


06-Tabs

IN ACTION

Portfolio

Content

  • fetch data from external url async, await.
  • useEffect for initialization
  • conditional rendering
  • conditional styling

07-Slider

IN ACTION

Gatsby-Airtable Project

Content

  • multiple useEffect
  • useEffect on specific var
  • useEffect cleanup

08-Lorem-Ipsum

Content

  • form handle single input
  • handle submit -> preventDefault
  • input return string
  • parseInt

09-Color-Generator

Values JS

values.js

Content

  • form handle single input
  • handle submit -> preventDefault
  • input return string
  • parseInt
  • fragment component
  • conditional class
className={`color ${index > 10 && "color-light"}`}
  • array.join()
  const arr = [3,4,5];
  const join_arr = arr.join('.') // join_arr = '3.4.5'
  • inline compoponent style
<article
  className={`color`}
  style={{ backgroundColor: `rgb(${bcg})` }}
>
</article>

  • rgbToHex function
  • copy value to clipboard
navigator.clipboard.writeText(hexValue)
  • color.hex -> not possible to destructure nont iterable property. instead send it to child as specific param.
<SingleColor
              key={index}
              {...color}
              hex={color.hex}
              index={index}
            >
</SingleColor>
  • useEffect cleanup, activated if component is unmounted.

10-Grocery-Bud

Content

  • conditional rendering
  • list managment, add ,edit ,delete.
  • function default values
  • array.filter
  • array.find
  • componenet useEffect dependancy
  • localStorage
  • useEffect for initialization

11-navbar

Content

  • img import
import logo from "./logo.svg";

<img src={logo} alt="logo" />
  • useRef to get element ref , for styling

12-sidebar-modal

Content

  • context hook
  • AppContext
  • children
  • custom hook
  • pass object in hook

13-stripe-submenus

Content

  • context hook
  • useRef
  • useContext
  • inline style
  • events mouseover, click
  • getBoundingClientRect for location ref.

14-cart

Content

  • useReducer - used for state managment

    state - object of states dispatch - functionality for updating states.

    • type -> action type
    • action -> arguments
  const [state, dispatch] = useReducer(reducer, initialState);

15-cocktails

React Router Fix

(Fix)[https://dev.to/dance2die/page-not-found-on-netlify-with-react-router-58mc]

CRA Fix


"build": "CI= react-scripts build",

Content

  • Route (react-route-dom)
    • BrowserRouter contain

      • linking components

        <Link to="{destination}"></dd>
        
      • routing components destinations

        • Switch to select from Route options , similar to reguler switch
        • path="*" similar to regular switch default
        • exact if not used it will be routed when it is part of other path like "/about" will call "/" and "/about"
        <Switch>
          <Route exact path="/">
            <Home></Home>
          </Route>
          <Route path="/about">
            <About></About>
          </Route>
          <Route path="*">
            <Error></Error>
          </Route>
        </Switch>
        
        • extract api data to more convinient object by destructure and build new object
        const newCocktails = drinks.map((item) => {
            const { idDrink, strDrink, strDrinkThumb, strAlcoholic, strGlass } = item;
            return {
              id: idDrink,
              name: strDrink,
              image: strDrinkThumb,
              info: strAlcoholic,
              glass: strGlass,
            };
        
        • context provider to transfer objects without prop drilling

        • uncontrolled input with useRef

          const searchValue = React.useRef("");
          .
          const searchCocktail = () => {
            setSearchTerm(searchValue.current.value);
            };
          .
          <input
              type="text"
              id="name"
              ref={searchValue}
              onChange={searchCocktail}
            />
        
        • useParams - to use url trnsfered params App.js
          <Route path="/cocktail/:id">
            <SingleCocktail />
          </Route>
        

        SingleCocktail.js

          const { id } = useParams();
        

16-Markdown-Preview

markdown cheetsheet

Content

  • use markdown component package

      npm install react-markdown
    
  • controlled input

      useState(markdown, setMardown)
    
      <textarea>
        value={markdown}
        onChange={(e) => setMarkdown(e.target.value)}
      </textarea>
    
    • convert to markdown
      <ReactMarkdown>{markdown}</ReactMarkdown>
    

17-Random-Person

Content

  • conditional render (loading)

  • useState

  • useEffect

  • destructure api object

  • read data dom object value

    • component
    <button
          key={index}
          className="icon"
          data-label={`${label}`}
          onMouseEnter={handleValue}
        ></button>
    
    • js read data value
    const newTitle = e.target.dataset.label;
    

18-Pagination

Content

  • custom hook
   const { loading, data } = useFetch();

  • conditional rendering
        <h1>{loading ? "loading..." : "pagination"}</h1>

  • convert array to array of arrays
const newFollowers = Array.from({ length: pages }, (_, index) => {
    const start = index * itemsPerPage;
    return followers.slice(start, start + itemsPerPage);
  });

19-Stock-Photos

Content

  • enviroment vars key=value key must start with REACT_APP_
  • scrollEvent add and remove when compoenents is off
 useEffect(() => {
   const event = window.addEventListener("scroll", () => {
     if (
       !loading &&
       window.innerHeight + window.scrollY >= document.body.scrollHeight - 200
     ) {
       setPage((oldPage) => {
         return oldPage + 1;
       });
     }
   });
   return () => window.removeEventListener("scroll", event);
 }, []);

Dark-Mode

Content

  • momentJs to format date

  • set html tag

    document.documentElement.classList = mode;
    
  • setting css varibles by class

.dark-theme {
  --clr-bcg: #282c35;
  --clr-font: #fff;
  --clr-primary: #ffa7c4;
}

.light-theme {
  --clr-bcg: #fff;
  --clr-font: #282c35;
  --clr-primary: #ffa7c4;
}

  • save theme to localStorage

Movie DB

react-projects-smilga's People

Contributors

shlev avatar

Watchers

 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.