Coder Social home page Coder Social logo

fancn21th / 1-004-todomvc-plus-react Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 381 KB

react + vite + typescript + storybook + styled component

HTML 1.97% TypeScript 82.78% JavaScript 4.39% CSS 10.85%
storybook react styled-components typescript vite custom-hooks design-system

1-004-todomvc-plus-react's Introduction

React In Typescript

+ styled component + storybook & on top of vite

In this project I would like to re-polish the old school todo list web app with the latest frontend technology.

They are:

Usage

  • storybook

    npm run storybook
  • mock design system

    npm run dev

How to type a React Component & Hook

Function Component

const foo: FunctionComponent<FooProps>  = ({...}) => { return ...}

Hook

  • useState

    const [todo, setTodo] = useState<string>("");
  • useReducer

    const reducer = (state: TodosState, action: TodosAction): TodosState => {
    ...
    };

Controlled Component

export const AddTodo: FunctionComponent<AddTodoProps> = ({
  label = "请输入",
  onAddTodo = () => {},
}) => {
  const [todo, setTodo] = useState<string>("");

  const onChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
    setTodo(e.target.value);
  };

  const onClick = function () {
    onAddTodo(todo);
    setTodo("");
  };

  return (
    <Div>
      <Input type="text" value={todo} placeholder={label} onChange={onChange} />
      <Button type="submit" onClick={onClick}>
        增加
      </Button>
    </Div>
  );
};

How to type others

Impersonate Native DOM

当你想包装另外一个 组件 的 时候 如何去 type props ? 需要一个个列出来吗 ?

type CustomProps = {
  foo?: string;
};
function Bar(props: CustomProps & TypeA & Type B) {
  ...
}

1-004-todomvc-plus-react's People

Contributors

fancn21th avatar

Watchers

 avatar  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.