local storage fix?

This commit is contained in:
2025-04-08 13:49:53 -05:00
parent 2119a653f1
commit 6ac319831f
+7 -1
View File
@@ -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"
required
onFocus={() => {
if (typeof window !== 'undefined') {
const savedName = localStorage.getItem('name');
if (savedName) setName(savedName);
}
}}
/>
</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"
required
onFocus={() => {
if (typeof window !== 'undefined') {
const savedEmail = localStorage.getItem('email');
if (savedEmail) setEmail(savedEmail);
}
}}
/>
</div>
@@ -153,8 +157,9 @@ const CommentSection: React.FC<CommentFormProps> = ({ postId }) => {
type="checkbox"
id="save-info"
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) => {
if (typeof window !== 'undefined') {
const saveInfo = e.target.checked;
localStorage.setItem('saveInfo', saveInfo.toString());
if (saveInfo) {
@@ -164,6 +169,7 @@ const CommentSection: React.FC<CommentFormProps> = ({ postId }) => {
localStorage.removeItem('name');
localStorage.removeItem('email');
}
}
}}
/>
<label htmlFor="save-info" className="ml-2 block text-sm text-primary-600">