components#Chat JavaScript Examples
The following examples show how to use
components#Chat.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: App.js From react-chat-app with MIT License | 6 votes |
App = () => {
const [mainComponent, setMainComponent] = useState("login")
useEffect(() => {
// This hook needs to be here because GH Pages doesn't allow subdirectories on default,
// making app unable to refresh on subdomain. So normally there is no need for conditional routes rendering
fb.auth.onAuthStateChanged((user) => {
if (user && user.displayName == null) {
setMainComponent("chat")
} else if (user && user.displayName !== null) {
setMainComponent("chat")
} else {
setMainComponent("login")
}
});
}, []);
return (
<div className="app">
<Router>
<AuthProvider>
<Switch>
{(mainComponent === "login") ?
<Route path="/react-chat-app/" component={Login} /> :
<Route exact path="/react-chat-app/" component={Chat} />}
<Route path="/signup" component={Signup} />
</Switch>
</AuthProvider>
</Router>
</div>
)
}
Example #2
Source File: App.jsx From react-chatengine-demo with MIT License | 6 votes |
App = () => {
const history = useHistory();
const { authUser } = useAuth();
const authResolved = useResolved(authUser);
// If the user is logged in it will prevent the
// user from seeing the login/signup screens
// by always redirecting to chat on auth change.
useEffect(() => {
if (authResolved) {
history.push(!!authUser ? '/' : '/login');
}
}, [authResolved, authUser, history]);
return authResolved ? (
<ChatProvider authUser={authUser}>
<div className="app">
<Switch>
<Route path="/" exact component={Chat} />
<Route path="/login" component={Login} />
<Route path="/signup" component={Signup} />
</Switch>
</div>
</ChatProvider>
) : (
<>Loading...</>
);
}