React util

React menu

採用遞迴做法把所有子清單都顯示出來

config.js

export default [
  {
    label: 'Foobar',
    children: [
      { label: 'Foo', parentLabel: 'Foobar' },
      { label: 'Bar', parentLabel: 'Foobar' },
    ],
  },
  {
    label: 'Joedoe',
    children: [
      {
        label: 'Joe',
        children: [{ label: 'Hello' }],
      },
      {
        label: 'Doe',
        children: [{ label: 'world!' }],
      },
    ],
  },
  { label: 'Logout' },
];

index.js

SubHeaderMenu.js

React util

1.如有一個共用的Component

不要於component的style 寫上如

這樣共用元素的頁面會互相覆蓋style 因為react不會重新render元素

2.使用Rich Editor

這裡使用Draft.js 做example

官方的usage只給了一般的editor

如要有上方按鈕需使用官方提供的richEditor範例

https://github.com/facebook/draft-js/blob/master/examples/rich/rich.html

我們使用時會先把它包成一個component在做引入

1.先新增RichEditor.js

2.添加兩份css

Draft.css

RichEditor.css

之後引入上面包好的Component

即可看到如下畫面

接著因為我們要將其存成immutable的markdown轉為html,須使用如下模組

https://github.com/sstur/draft-js-export-html

如上使用即可

使用Material UI

為原本的Materialize css包成的套件。

http://www.material-ui.com/#/components/list

ICON: https://material.io/icons/#ic_swap_horiz

使用 I18N

個人推薦:https://react.i18next.com/guides/quick-start

他是i18next的react版本,nodejs也有類似,且用法相同,可共用程式。

https://github.com/formatjs/react-intl 需要且defineMessage與defaultMessage較為繁瑣。

React hook with lodash Debounce

e.g.

Last updated

Was this helpful?