@@ -25,10 +25,9 @@ export const JwtInputComponent: React.FC<JwtInputComponentProps> = ({
25
25
languageCode,
26
26
dictionary,
27
27
} ) => {
28
- const [ autoFocusEnabled , setAutofocusEnabled ] = useState ( ( ) => {
29
- const saved = localStorage . getItem ( "autofocus-enabled" ) ;
30
- return saved ? ! ! JSON . parse ( saved ) : false
31
- } ) ;
28
+ const [ autoFocusEnabled , setAutofocusEnabled ] = useState < boolean | undefined > (
29
+ undefined
30
+ ) ;
32
31
const handleJwtChange$ = useDecoderStore ( ( state ) => state . handleJwtChange ) ;
33
32
const jwt$ = useDecoderStore ( ( state ) => state . jwt ) ;
34
33
const decodeErrors$ = useDecoderStore ( ( state ) => state . decodingErrors ) ;
@@ -52,9 +51,14 @@ export const JwtInputComponent: React.FC<JwtInputComponentProps> = ({
52
51
} ;
53
52
54
53
const handleCheckboxChange = ( selected : boolean ) => {
55
- localStorage . setItem ( "autofocus-enabled" , JSON . stringify ( selected ) )
56
- setAutofocusEnabled ( selected )
57
- }
54
+ localStorage . setItem ( "autofocus-enabled" , JSON . stringify ( selected ) ) ;
55
+ setAutofocusEnabled ( selected ) ;
56
+ } ;
57
+
58
+ useEffect ( ( ) => {
59
+ const saved = localStorage . getItem ( "autofocus-enabled" ) ;
60
+ setAutofocusEnabled ( saved ? ! ! JSON . parse ( saved ) : false ) ;
61
+ } , [ ] ) ;
58
62
59
63
useEffect ( ( ) => {
60
64
setToken ( jwt$ ) ;
@@ -64,7 +68,10 @@ export const JwtInputComponent: React.FC<JwtInputComponentProps> = ({
64
68
< >
65
69
< div style = { { display : "flex" , justifyContent : "space-between" } } >
66
70
< span className = { styles . headline } > { dictionary . headline } </ span >
67
- < CheckboxComponent isSelected = { autoFocusEnabled } onChange = { e => handleCheckboxChange ( e ) } >
71
+ < CheckboxComponent
72
+ isSelected = { autoFocusEnabled }
73
+ onChange = { ( e ) => handleCheckboxChange ( e ) }
74
+ >
68
75
< span className = { styles . checkbox__label } > Enable auto-focus</ span >
69
76
</ CheckboxComponent >
70
77
</ div >
@@ -99,7 +106,13 @@ export const JwtInputComponent: React.FC<JwtInputComponentProps> = ({
99
106
) ,
100
107
} }
101
108
>
102
- < JwtEditorComponent token = { token } handleJwtChange = { handleJwtChange } autoFocus = { autoFocusEnabled } />
109
+ { autoFocusEnabled !== undefined ? (
110
+ < JwtEditorComponent
111
+ token = { token }
112
+ handleJwtChange = { handleJwtChange }
113
+ autoFocus = { autoFocusEnabled }
114
+ />
115
+ ) : null }
103
116
</ CardComponent >
104
117
</ >
105
118
) ;
0 commit comments