首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我不知道如何访问UpdateHeight();用于反应-可滑动路由

我不知道如何访问UpdateHeight();用于反应-可滑动路由
EN

Stack Overflow用户
提问于 2022-09-29 14:20:14
回答 1查看 39关注 0票数 -1

仪表板加载和问题,我必须滑动和滑动回来,以更新高度。因此,我试图把它作为道具和useEffect来更新高度。我只是不明白这是怎么回事。

代码语言:javascript
复制
import React, { useState, useEffect } from "react";
import { BrowserRouter as Router, Route, Link } from "react-router-dom";
import Navbar from "./components/layout/Navbar";
import Dashboard from "./components/dashboard/Dashboard";
import Notifications from "./components/dashboard/Notifications";
import Profile from "./components/profile/Profile";
import SignIn from "./components/auth/SignIn";
import SignUp from "./components/auth/SignUp";
import './App.css';
import SwipeableRoutes from "react-swipeable-routes";
import SwipeableViews from 'react-swipeable-views';

const App = (props) => {

  useEffect(() => {
    // Update the document title using the browser API
    props.swipeableViews.UpdateHeight();
  });

  return (
    <div className="App">
      <Navbar />

      <SwipeableRoutes animateHeight>
        <Route path="/signup" component={SignUp} />
        <Route path="/signin" component={SignIn} />

        <Route exact path="/" component={Dashboard} />
        <Route path="/notifications" component={Notifications} />
        <Route path="/profile" component={Profile} />
      </SwipeableRoutes>
    </div>
  );
};

export default App;
EN

回答 1

Stack Overflow用户

发布于 2022-09-29 18:19:29

我的一个朋友帮了我。问题很容易解决。

代码语言:javascript
复制
// Declare ref
var updateh = React.useRef();


<SwipeableRoutes
  animateHeight={true}
  // Accroding to the doc, you should just calla hook function called "action" and assign it to the ref to be able to call the callback functions inside it.
  action={(hooks) => {
    updateh.current = hooks;
  }}
>
  <Route path="/signup" component={SignUp} />
  <Route path="/signin" component={SignIn} />
  <Route exact path="/">
    <Dashboard updateh={updateh} />
  </Route>
  <Route path="/notifications" component={Notifications} />
  <Route path="/profile" component={Profile} />
</SwipeableRoutes>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73897121

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档