小编Reh*_*han的帖子

如何在 NextJS 中以多步骤形式传递数据?

我最近开始使用 NextJS 和 React。

我正在尝试在我的应用程序中实现多页面表单,但我不知道如何保留并将表单数据从一个页面传递到另一页面。

关于使用状态管理库和上下文 API 有很多指南,但它们要么在 ReactJS 中,要么定义了不同组件之间的使用。

我的 _app.js 看起来像这样:

const AppComponent = ({ Component, pageProps, currentUser }) => {
  return (
    <div>
      <AppWrapper>
        <Header currentUser={currentUser} />
        <Component {...pageProps} />
      </AppWrapper>
    </div>
  );
};
AppComponent.getInitialProps = async (appContext) => {
  const client = buildClient(appContext.ctx);

  const { data } = await client.get('/api/client/currentuser');
  let pageProps = {};
  if (appContext.Component.getInitialProps) {
    pageProps = await appContext.Component.getInitialProps(appContext.ctx);
  }
  return {
    pageProps,
    ...data,
  };
};

export default AppComponent
Run Code Online (Sandbox Code Playgroud)

上下文状态.js

import { createContext, useContext …
Run Code Online (Sandbox Code Playgroud)

state-management reactjs react-redux next.js

5
推荐指数
1
解决办法
4430
查看次数

如何使用layoutDirection在Android中动态镜像整个布局?

我试图建立一个android应用程序的前端视图。我必须将整个显示动态地推到屏幕的右侧。

我想将整个相对布局推到屏幕的右侧。

以下是我的XML代码:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/message_single_layout"
        android:padding="10dp"
        android:layout_gravity=""
        android:weightSum="10">
        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/message_profile_layout"
            android:layout_width="36dp"
            android:layout_height="36dp"
            android:layout_weight="0"
            android:src="@drawable/default_avatar" />

        <TextView
            android:layout_alignParentRight="true"
            android:id="@+id/message_text_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/name_text_layout"
            android:layout_marginLeft="10dp"
            android:layout_toEndOf="@+id/message_profile_layout"
            android:padding="10dp"
            android:background="@drawable/their_message"
            android:text="Message Text"
            android:textColor="@color/colorPrimary"
            android:textSize="14sp" />

        <TextView
            android:id="@+id/name_text_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="10dp"
            android:layout_toEndOf="@+id/message_profile_layout"
            android:text="Display Name"
            android:textColor="@android:color/black"
            android:textSize="15sp"
            android:textStyle="bold"

            />

        <TextView
            android:id="@+id/time_text_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/message_text_layout"
            android:layout_marginStart="-15dp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="4dp"
            android:layout_toEndOf="@+id/name_text_layout"
            android:text="00:00"
            android:textSize="12sp" />

        <ImageView
            android:id="@+id/message_image_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/message_text_layout"
            android:layout_alignStart="@+id/message_text_layout"
            android:layout_alignParentEnd="true"
            android:layout_marginStart="0dp"
            android:layout_marginLeft="0dp"
            android:layout_marginTop="-6dp"
            android:layout_marginEnd="9dp"
            android:layout_toEndOf="@+id/message_profile_layout"
            android:padding="0dp"
            android:scaleType="centerCrop" />

    </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我想动态地做。我试图改变gravity …

java xml android android-layout

4
推荐指数
1
解决办法
132
查看次数