reorder list

export const langMapDataA = {
  sports: "Sports",
  casino: "Casino",
  esports: "E-Sports",
};

const reCraftArray = Object.keys(viewLang).map((key) => ({
  key: key,
  value: viewLang[key],
}));

const [list, setList] = useState(reCraftArray);

React.useEffect(() => {
  const reOrderSort = list.reduce((a, c) => {
    return a.concat(c.key);
  }, []);
  setProp((props) => (props.order = reOrderSort));
}, [list]);

// 每次list有變化都再變成陣列一次,然後再傳給元件

Array.prototype.slice()

const animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];

console.log(animals.slice(2));
// expected output: Array ["camel", "duck", "elephant"]

console.log(animals.slice(2, 4));
// expected output: Array ["camel", "duck"]

console.log(animals.slice(1, 5));
// expected output: Array ["bison", "camel", "duck", "elephant"]

slice就像:我要刪除前面的二個! animals.slice(2)
(實際上是index為2保留,之後的也保留。刪掉0、1)
我要刪除前面的二個,第四個以後的也都刪掉 animals.slice(2, 4)
(實際上是index為2的保留,保留到四的以前…不包含四,記起來比較麻煩。)
只刪除一個的情況:
我要刪除第二個,只刪除一個(第二個參數變成要刪幾個)
months.splice(2, 1);

react-select 小教學

react-select

import React, { Component } from 'react'
import Select from 'react-select'

const options = [
  { value: 'chocolate', label: 'Chocolate' },
  { value: 'strawberry', label: 'Strawberry' },
  { value: 'vanilla', label: 'Vanilla' }
]

const MyComponent = () => (
  <Select options={options} />
)
menuIsOpen={true}

貼上這個可以每次都是展開的,要inspect比較方便

blurInputOnSelect

這個props可以讓選擇後失去焦點,不會有focus效果

要客製化style的話,可以寫一個客製化風格物件,
文件教學在這。另外可以看DOM結構的classname來對應

const customStyles = {
  option: (provided, state) => ({
    ...provided,
    borderBottom: '1px dotted pink',
    color: state.isSelected ? 'red' : 'blue',
  }),
  control: () => ({
    // none of react-select's styles are passed to <Control />
    width: 200,
  }),
  singleValue: (provided, state) => {
    const opacity = state.isDisabled ? 0.5 : 1;
    const transition = 'opacity 300ms';

    return { ...provided, opacity, transition };
  }
}

  const App = () => (
    <Select
      styles={customStyles}
      options={...}
    />
  );

不過做這個我覺得也許可以搭配Storybook

peerDependencies, devDependencies, dependencies

dependencies
跑這個程式需要的套件

devDependencies
開發的時候需要的套件,例如Jest之類的測試工具,但是執行的時候不需要(例如babel)

peerDependencies
告訴安裝這個套件的人,需要自己安裝什麼套件

--save-dev
存到devDependencies,也就是-D
--save
存到dependencies

參考文章:
Types of dependencies
↑解釋最清楚
What’s the difference between dependencies, devDependencies and peerDependencies in npm package.json file?
↑解釋的不怎樣。