fixed nextjs ssg build issue

This commit is contained in:
Ren Amamiya
2023-04-21 16:41:04 +07:00
parent 9fdf2eb81c
commit b64ed8b587
18 changed files with 107 additions and 106 deletions

View File

@@ -7,19 +7,18 @@ import { createNote, getNoteByID } from '@utils/storage';
import { getParentID } from '@utils/transform';
import useLocalStorage from '@rehooks/local-storage';
import { memo, useCallback, useContext, useEffect, useRef, useState } from 'react';
import { memo, useCallback, useContext, useEffect, useState } from 'react';
export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
const [pool, relays]: any = useContext(RelayContext);
const [activeAccount]: any = useLocalStorage('account', {});
const [event, setEvent] = useState(null);
const unsubscribe = useRef(null);
const content = event ? contentParser(event.content, event.tags) : '';
const fetchEvent = useCallback(async () => {
unsubscribe.current = pool.subscribe(
const unsubscribe = pool.subscribe(
[
{
ids: [id],
@@ -50,9 +49,13 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
unsubscribeOnEose: true,
}
);
return () => {
unsubscribe();
};
}, [activeAccount.id, id, pool, relays]);
const checkNoteExist = useCallback(async () => {
const checkNoteIsSaved = useCallback(async () => {
getNoteByID(id)
.then((res) => {
if (res) {
@@ -65,14 +68,16 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
}, [fetchEvent, id]);
useEffect(() => {
checkNoteExist();
let ignore = false;
if (!ignore) {
checkNoteIsSaved();
}
return () => {
if (unsubscribe.current) {
unsubscribe.current();
}
ignore = true;
};
}, [checkNoteExist]);
}, [checkNoteIsSaved]);
if (event) {
return (