Archived
local storage fix?
This commit is contained in:
@@ -110,8 +110,10 @@ const CommentSection: React.FC<CommentFormProps> = ({ postId }) => {
|
|||||||
className="w-full px-4 py-2 border border-primary-300 rounded-md focus:outline-none focus:ring-2 focus:ring-accent focus:border-transparent"
|
className="w-full px-4 py-2 border border-primary-300 rounded-md focus:outline-none focus:ring-2 focus:ring-accent focus:border-transparent"
|
||||||
required
|
required
|
||||||
onFocus={() => {
|
onFocus={() => {
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
const savedName = localStorage.getItem('name');
|
const savedName = localStorage.getItem('name');
|
||||||
if (savedName) setName(savedName);
|
if (savedName) setName(savedName);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -127,8 +129,10 @@ const CommentSection: React.FC<CommentFormProps> = ({ postId }) => {
|
|||||||
className="w-full px-4 py-2 border border-primary-300 rounded-md focus:outline-none focus:ring-2 focus:ring-accent focus:border-transparent"
|
className="w-full px-4 py-2 border border-primary-300 rounded-md focus:outline-none focus:ring-2 focus:ring-accent focus:border-transparent"
|
||||||
required
|
required
|
||||||
onFocus={() => {
|
onFocus={() => {
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
const savedEmail = localStorage.getItem('email');
|
const savedEmail = localStorage.getItem('email');
|
||||||
if (savedEmail) setEmail(savedEmail);
|
if (savedEmail) setEmail(savedEmail);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -153,8 +157,9 @@ const CommentSection: React.FC<CommentFormProps> = ({ postId }) => {
|
|||||||
type="checkbox"
|
type="checkbox"
|
||||||
id="save-info"
|
id="save-info"
|
||||||
className="h-4 w-4 text-accent border-primary-300 rounded focus:ring-accent"
|
className="h-4 w-4 text-accent border-primary-300 rounded focus:ring-accent"
|
||||||
checked={localStorage.getItem('saveInfo') === 'true'}
|
checked={typeof window !== 'undefined' && localStorage.getItem('saveInfo') === 'true'}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
const saveInfo = e.target.checked;
|
const saveInfo = e.target.checked;
|
||||||
localStorage.setItem('saveInfo', saveInfo.toString());
|
localStorage.setItem('saveInfo', saveInfo.toString());
|
||||||
if (saveInfo) {
|
if (saveInfo) {
|
||||||
@@ -164,6 +169,7 @@ const CommentSection: React.FC<CommentFormProps> = ({ postId }) => {
|
|||||||
localStorage.removeItem('name');
|
localStorage.removeItem('name');
|
||||||
localStorage.removeItem('email');
|
localStorage.removeItem('email');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<label htmlFor="save-info" className="ml-2 block text-sm text-primary-600">
|
<label htmlFor="save-info" className="ml-2 block text-sm text-primary-600">
|
||||||
|
|||||||
Reference in New Issue
Block a user