DictComponent.tsx 908 B

12345678910111213141516171819202122232425262728293031323334
  1. import { useState, useEffect } from "react";
  2. import { useAppSelector } from "../../hooks";
  3. import { lookup, lookupWord } from "../../reducers/command";
  4. import store from "../../store";
  5. import Dictionary from "./Dictionary";
  6. export interface IWidgetDict {
  7. word?: string;
  8. }
  9. const DictComponentWidget = ({ word }: IWidgetDict) => {
  10. const [wordSearch, setWordSearch] = useState(word);
  11. //接收查字典消息
  12. const searchWord = useAppSelector(lookupWord);
  13. useEffect(() => {
  14. console.log("get command", searchWord);
  15. if (typeof searchWord === "string" && searchWord !== wordSearch) {
  16. setWordSearch(searchWord);
  17. }
  18. }, [searchWord]);
  19. return (
  20. <Dictionary
  21. word={wordSearch}
  22. compact={true}
  23. onSearch={(value: string) => {
  24. console.debug("onSearch", value);
  25. store.dispatch(lookup(value));
  26. }}
  27. />
  28. );
  29. };
  30. export default DictComponentWidget;