@@ -66,30 +66,6 @@ export default class NavComponent extends React.Component {
66
66
setUuid ( uuid ) ;
67
67
}
68
68
69
- /**
70
- * Saves the UUID type to localStorage.
71
- *
72
- * @param {string } type - The UUID type to save.
73
- * @return {void }
74
- */
75
- saveSelectedUuidType = ( type ) => {
76
- // Save the UUID type to localStorage
77
- localStorage . setItem ( 'uuidType' , type ) ;
78
- }
79
-
80
- /**
81
- * Retrieves the UUID type from localStorage.
82
- *
83
- * @return {string } The UUID type from localStorage or 'v4' if it is not found.
84
- */
85
- getStoredUuidType = ( ) => {
86
- // Retrieve the UUID type from localStorage
87
- let type = localStorage . getItem ( 'uuidType' ) ;
88
-
89
- // Return the UUID type or 'v4' if it is not found
90
- return type ? type : 'v4' ;
91
- }
92
-
93
69
/**
94
70
* Render method for the NavComponent.
95
71
*
@@ -101,7 +77,14 @@ export default class NavComponent extends React.Component {
101
77
*/
102
78
render ( ) {
103
79
// State to store the selected UUID type
104
- const [ selectedUuidType , setSelectedUuidType ] = React . useState ( this . getStoredUuidType ( ) ) ;
80
+ const [ selectedUuidType , setSelectedUuidType ] = React . useState (
81
+ localStorage . getItem ( 'uuidType' ) || 'v4'
82
+ ) ;
83
+
84
+ // Effect to store the selected UUID type in localStorage
85
+ React . useEffect ( ( ) => {
86
+ localStorage . setItem ( 'uuidType' , selectedUuidType ) ;
87
+ } , [ selectedUuidType ] ) ;
105
88
106
89
// State to store the generated UUID
107
90
const [ generatedUuid , setGeneratedUuid ] = React . useState ( '' ) ;
@@ -151,10 +134,7 @@ export default class NavComponent extends React.Component {
151
134
< p className = "control" >
152
135
< span className = "select is-link is-small" >
153
136
{ /* Dropdown menu for UUID types */ }
154
- < select onChange = { ( e ) => {
155
- setSelectedUuidType ( e . target . value ) ;
156
- this . saveSelectedUuidType ( e . target . value ) ;
157
- } } >
137
+ < select onChange = { ( e ) => setSelectedUuidType ( e . target . value ) } >
158
138
{ uuidTypes . map ( type => (
159
139
< option key = { type } value = { type } selected = { selectedUuidType === type } >
160
140
{ type }
0 commit comments