I am using next.js on "next": "13.4.19". the project structure is --app -- layout.tsx -- page.tsx -- [id] --page.tsx
in the [id] page.tsx,
"use client"
import { Editor } from '@/components/editor';
import { useState, useRef, useEffect, useMemo } from 'react'
export default async function PipelineDesignerEditorPage(
{ params }: { params: { pipelineId: string } }
) {
console.log('params.pipelineId',params.pipelineId);
const [loding, setLoding] = useState(false);
const [pipelineData, setPipelineData] = useState({});
useEffect(() => {
setLoding(true);
let data = getPipeline(params.pipelineId);
setPipelineData(data);
setLoding(false);
}, []);
return (
<div style={{ width: '100%', height: `calc(100vh - 65px)` }}>
<Editor pipeline={pipeline} />
</div>
)
}
an error 'Error: async/await is not yet supported in Client Components, only Server Components. This error is often caused by accidentally adding 'use client'
to a module that was originally written for the server.' appears.
I found this page is being rendered in the server side, so I modified a bit
'user client'
import { Editor } from '@/components/editor';
import { getPipeline } from '@/lib/pipelines/storage';
import { useState, useRef, useEffect, useMemo } from 'react'
export default async function PipelineDesignerEditorPage(
{ params }: { params: { pipelineId: string } }
) {
console.log('params.pipelineId',params.pipelineId);
const pipeline = await getPipeline(params.pipelineId);
const [loding, setLoding] = useState(false);
useEffect(() => {
console.log('useEffect');
setLoding(true);
}, []);
return (
<div style={{ width: '100%', height: `calc(100vh - 65px)` }}>
<Editor pipeline={pipeline} />
</div>
)
}
it still doesn't work unless useEffect and useState is removed away.
Does it mean I can't use useState and useEffect in app->[id]->page.tsx, what about click, loading actions which needs to use useState and useEffect