Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

new Map() collection in react state

function MapComponent(){
  const [myMap, setMyMap] = useState(new Map());
  const updateMap = (k,v) => {
    setMyMap(new Map(myMap.set(k,v)));
  }
  return(
    <ul>
      {[...myMap.keys()].map(k => (
        <li key={k}>myMap.get(k)</li>
      ))}
    </ul>
  );
}
Source by medium.com #
 
PREVIOUS NEXT
Tagged: #collection #react #state
ADD COMMENT
Topic
Name
7+9 =