2022-05-01から1ヶ月間の記事一覧

Javascript: Skip an element array and make a new array

var newArray = array.reduce(function(result, hoge) { if (some condition) { result.push(hoge); } return result; }, []); or var newArray = array.filter(function(hoge) { if (some condition) { return hoge; } });

React: Outside Click Detection

import React, { useRef, useEffect } from "react"; export default SomeFunctionComponent(props) { const elementRef = useRef(null); useEffect(() => { function handleOutsideClick(event) { if (ref.current && !ref.current.contains(event.target))…