gpt4 book ai didi

reactjs - 我可以在React的另一个组件中重用一个组件的片段吗?

转载 作者:行者123 更新时间:2023-12-03 12:38:13 24 4
gpt4 key购买 nike

我在React组件中有一个片段,我想在一个单独的组件中使用它,有什么办法可以重用Fragment?
这是我要访问的第一个组件的片段:

  <Fragment>
{this.state.sharing === false ? (
<div className="video-container">
{this.renderNoInternet()}
{this.renderRedirect()}
<AudoUpdatePopup />
<Header
me={this.state.me}
logoutHandler={this.logoutHandler}
changeCameraStatus={this.changeCameraStatus}
changeMicrophoneStatus={this.changeMicrophoneStatus}
audioDevices={this.state.audioDevices}
videoDevices={this.state.videoDevices}
onChangeCamera={this.changeCamerahandler}
onChangeMicrophone={this.changeMicrophoneHandler}
knocking={{
beingKnocked: this.state.beingKnocked.status,
knocking: this.state.knocking.status,
callAccepted: this.state.callAccepted,
}}
/>

<div className="user-container">
{this.state.me.cameraStatus === "Out"
? null
: this.state.coworkers.map((user, index) => {
if (user.id !== parseInt(localStorage.getItem("me.id")))
return (
<UserThumbnail
onClick={this.startCall}
key={index}
user={user}
knocking={{
beingKnocked: this.state.beingKnocked.status,
knocking: this.state.knocking.status,
callAccepted: this.state.callAccepted,
}}
/>
);
else return null;
})}
<div
className={
this.state.beingKnocked.status === true ||
this.state.callAccepted === true ||
this.state.knocking.status === true
? "user-video opacity-cont-hide"
: "user-video"
}
style={{ marginLeft: "8px" }}
>
<Link
to="/InviteCoworker"
onClick={() => {
try {
WebRTC.leaveWorkspace(this.workspaceId);
WebRTC.disconnect();
} catch (e) {}
}}
>
<button className="invite-button">
<img
alt="User"
src={require("../../assets/images/add-button.jpg")}
/>
<p className="invite-text">Invite</p>
</button>
</Link>
</div>
{this.myIndex !== -1 ? (
<UserThumbnail
onClick={this.startCall}
user={this.state.coworkers[this.myIndex]}
knocking={{
beingKnocked: this.state.beingKnocked.status,
knocking: this.state.knocking.status,
}}
/>
) : null}
{this.state.me.cameraStatus === "Out" &&
this.state.activeUsers >= 0 ? (
<p className="set-status-text">
{this.activeUsersText}
<br />
<br />
<p
dangerouslySetInnerHTML={this.createNoPermissionMarkup()}
></p>
</p>
) : null}
{this.state.coworkers.length === 0 &&
this.state.me.cameraStatus !== "Out" ? (
<p className="set-status-text">
<br />
Feels a little quiet in here.
<br />
Invite some friends or coworkers.
</p>
) : null}

{this.state.beingKnocked.status === true ? (
<BeingKnocked
payload={this.state.beingKnocked}
streams={this.streams}
hangUpCall={this.hangupCall.bind(this)}
acceptCall={this.acceptCall.bind(this)}
/>
) : null}
{this.state.knocking.status === true ? (
<Knocking
payload={this.state.knocking}
streams={this.streams}
hangUpCall={this.hangupCall.bind(this)}
/>
) : null}
{this.state.callAccepted === true ? (
<CallScreen
{ ...this.props } me={this.state.me} coworkers={this.state.coworkers}
knocking={{
beingKnocked: this.state.beingKnocked.status,
knocking: this.state.knocking.status,
callAccepted: this.state.callAccepted,
}}
// next try props=this.props state=this.state, then try props=...this.props state=...this.state
// hangUpCall={this.hangupCall.bind(this)}
// secondPartyStream={this.state.secondPartyStream}
// startScreenShare={this.startScreenShare.bind(this)}
/>
) : null}
</div>
</div>
) : (
<ShareScreen
sharerVideo={this.state.sharerStream}
myVideo={this.state.me.myClearVideo}
micLevel={this.state.me.micAudioLevel}
stopScreenShare={this.state.sharer ? this.hangupCall : this.stopScreenShare}
//stopScreenShare={this.hangupCall} // This line of code will hangup the call when the screen share is over (MARK)
sharer={this.state.sharer}
secondPartyStream={this.state.secondPartyStream}
/>
)}

我想在另一个组件中访问它:
import React, { Component, Fragment } from "react";
import UserThumbnail from "./UserThumbnail";
import AudoUpdatePopup from "./AudoUpdatePopup";
import { Link } from "react-router-dom";
import WebRTC from "../../assets/js/webrtc.js";
import BeingKnocked from "./screens/BeingKnocked";
import Knocking from "./screens/Knocking";
import CallScreen from "./screens/CallScreen";
import Header from "./Header";
import Dashboard from "./Dashboard";

// Styling
const h1Style = {
width: '107px',
height: '27px',
fontFamily: 'Lato',
fontSize: '22px',
fontWeight: 'bold',
fontStretch: 'normal',
fontStyle: 'normal',
lineHeight: 'normal',
letterSpacing: '-0.73px',
textAlign: 'center',
color: "#000062",
};
const modalStyle = {
display: 'none',
position: 'fixed',
zIndex: 1,
};
const modalContentStyle = {
position: 'absolute',
backgroundColor: 'white',
};

export class AddressingPopup extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
// Fragment goes here
);
}
}
export default AddressingPopup;
我只需要第二个片段的第一个片段具有相同的功能。

最佳答案

如果我理解正确,则希望使用上一个组件到第二个组件的设计和功能。在这种情况下,您可以简单地导出第一个组件,然后将其导入第二个组件。然后,您可以在return函数中添加该组件。除此之外,不可能使用从一个文件到另一个文件的代码

关于reactjs - 我可以在React的另一个组件中重用一个组件的片段吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65347074/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com