English 中文(简体)
如何培养客户
原标题:How to nest client component NextJS

I m New to NextJS and response and I m seeking to knowledge composition.

I have a client component called Form.jsx like

export default function FormHome() {
   ... tons of client side javascript function ...
   const [open, setOpen] = React.useState(false);
   
function onSubmit(data: z.infer<typeof FormSchema>) {
    startTransition(async () => {
      ... other code ...

        setOpen(true);
      });
    });
  }


   if(isDesktop) {
      return (
      <Form {...form}>
        ... a very long block of javascript that interacts with the function above...
        <Dialog open={open} onOpenChange={setOpen}>
        ... some other code ...
        </Dialog>
      </Form>
      );
   }
   
      return (
      <Form {...form}>
        ... a very long block of javascript that interacts with the function above...
        <Drawer open={open} onOpenChange={setOpen}>
        ... some other code ...
        </Drawer>
        <AlertDialog open={openAlert} onOpenChange={setOpenAlert}>
        </AlertDialog>
      </Form>
      );
}

之后,我有<代码>网页.tsx。 公正

export default function Home() {
  return <Form />;
}

在同一<代码>Form.jsx的客户部分中,有某种方式可以确定以下各项:<Drawer>,<Dialog>,等等,但通过这些变量(例如,我需要通过{>><>>>>>>>>>>>和Open})。

问题回答

If I understand correctly, what you want to do is to extract some of your JSX code into a separate component. It could be done like this:

// name this component whatever you want
function DrawerWrapper(props) {
  return (
    <Drawer open={props.open} onOpenChange={props.onOpenChange}>
        ... some other code ...
    </Drawer>
  );
}

export default function FormHome() {
  const [open, setOpen] = React.useState(false);

  return (
     <Form {...form}>
        <DrawerWrapper open={open} onOpenChange={setOpen} />
     </Form>
  );
}

不过,如果你的习俗部分有许多法典,我建议为它建立一个单独的档案,然后进口。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签