studys.tsx 1.97 KB
Newer Older
mayi's avatar
mayi committed
1 2 3
import * as React from "react";
import { Component } from "react";
import styles from "./studys.module.css";
4 5
import { Input, Button, Menu, Dropdown, message } from "antd";
import { DownOutlined } from "@ant-design/icons";
mayi's avatar
mayi committed
6 7
import { useSelector } from "../../redux/hooks";
import { useDispatch } from "react-redux";
8 9 10 11 12 13 14
import { type } from "os";

import {
  changeInputActionCreator,
  addCityActionCreator,
} from "../../redux/citys/cityActions";

mayi's avatar
mayi committed
15 16
export const Studys: React.FC = () => {
  const dispatch = useDispatch();
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
  const cityList: { name: string }[] = useSelector(
    (state) => state.city.cityLists
  );
  const cityName = useSelector((state) => state.city.cityName);
  const cityInput = useSelector((state) => state.city.cityInput);

  // const onClick = ({ key }) => {
  //   message.info(`Click on item ${key}`);
  // };
  // const menu = (
  //   <Menu onClick={onClick}>
  //     <Menu.Item key="1">1st menu item</Menu.Item>
  //     <Menu.Item key="2">2nd menu item</Menu.Item>
  //     <Menu.Item key="3">3rd menu item</Menu.Item>
  //   </Menu>
  // );
  const addCity = () => {
    dispatch(addCityActionCreator(cityInput));
  };
  const changeInput = (e) => {
mayi's avatar
mayi committed
37
    // console.log(e.target.value)
38 39 40

    dispatch(changeInputActionCreator(e.target.value));
  };
mayi's avatar
mayi committed
41 42 43 44 45
  return (
    <>
      {/* 做一个与header.tsx类似的页面 */}
      <h1>练习页面</h1>
      <div>
46 47 48 49 50 51 52 53 54 55 56
        <div>
          添加你想去的城市:
          <input
            placeholder="Basic usage"
            onChange={changeInput}
            style={{ width: 200 }}
            value={cityInput}
          />
          <Button type="primary" onClick={addCity}>
            添加
          </Button>
mayi's avatar
mayi committed
57 58
        </div>
        <h1>我最喜欢的城市:{cityName}</h1>
59 60 61 62 63 64 65 66 67 68
        <h1>
          我想去的城市:
          {cityList.map((item, index) => {
            return (
              <>
                <span>{item.name},</span>
              </>
            );
          })}
        </h1>
mayi's avatar
mayi committed
69 70 71 72
      </div>
    </>
  );
};