@@ -14,6 +14,7 @@ import {
1414 pluginLabelStyles ,
1515 pluginValueStyles ,
1616} from "../styles/pluginStyles" ;
17+ import { useCallback , useState } from "react" ;
1718
1819interface ForEachConfig_t {
1920 testVariable : string ;
@@ -42,10 +43,19 @@ function ForEach() {
4243
4344 const config : ForEachConfig_t = useConfig ( ) as ForEachConfig_t ;
4445
46+ const [ index , setIndex ] = useState ( 1 ) ;
47+
4548 // Extract the variables from config panel
4649 const [ testVariableValue ] = useVariable ( config . testVariable ) ;
4750 const [ urlParamToReadValue ] = useVariable ( config . urlParamToRead ) ;
48- const [ urlParameter , setUrlParameter ] = useUrlParameter ( urlParamToReadValue ?. defaultValue ?. value ?? '' ) ;
51+
52+ const urlParamToRead = urlParamToReadValue ?. defaultValue ?. value ?? '' ;
53+ const [ urlParameter , setUrlParameter ] = useUrlParameter ( urlParamToRead ) ;
54+
55+ const updateUrlParameter = useCallback ( ( ) => {
56+ setUrlParameter ( `test-${ urlParamToRead } -${ index } ` ) ;
57+ setIndex ( index + 1 ) ;
58+ } , [ index , urlParamToRead ] ) ;
4959
5060 return (
5161 < div style = { pluginContainerStyles } >
@@ -81,7 +91,7 @@ function ForEach() {
8191 } }
8292 >
8393 { JSON . stringify ( urlParameter , undefined , 2 ) }
84- < button onClick = { ( ) => setUrlParameter ( 'test' ) } > Set URL Param to 'test'</ button >
94+ < button onClick = { updateUrlParameter } > Set URL Param to 'test- { urlParamToRead } - { index } '</ button >
8595 </ pre >
8696 </ div >
8797 < div style = { pluginStatusItemStyles } >
0 commit comments