From 40c4717bc1cc6d088b442213f922db541309550d Mon Sep 17 00:00:00 2001 From: Ahmed Kamel Taha Date: Sat, 12 Sep 2020 02:44:54 +0200 Subject: [PATCH] fix replace to replace all --- src/useDropdown.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/useDropdown.js b/src/useDropdown.js index 839736ad..5fbe5549 100644 --- a/src/useDropdown.js +++ b/src/useDropdown.js @@ -2,7 +2,9 @@ import React, { useState } from "react"; const useDropdown = (label, defaultState, options) => { const [state, updateState] = useState(defaultState); - const id = `use-dropdown-${label.replace(" ", "").toLowerCase()}`; + // if the replace pattern is a string only the first occurrence will be replaced + // so to replace all use a regex with g flag + const id = `use-dropdown-${label.replace(/ /g, "").toLowerCase()}`; const Dropdown = () => (