小编Roh*_*utt的帖子

为什么 componentDidmount 调用了两次

我在componentDidMount中有 React 组件从服务器获取数据。问题是componentDidMount被调用了两次,API 也被调用了两次。我有一个视图增量 API,例如 YouTube 视频视图,由于两次 API 调用,在数据库中增量两次。

class SingleVideoPlay extends React.Component {
    constructor(props) {
        super(props);
        this.player = React.createRef();
    }
    state = {
        autoPlay: true,
        relatedVideos: [],
        video: null,
        user: null,
        comments: [],
        commentInput: {
            value: '',
            touch: false,
            error: false
        },
        following: false,
        tab: 'comments'
    };
    _Mounted = false;

    componentDidMount() {
        this._Mounted = true;
        if (this._Mounted) {
            const videoId = this.props.match.params.id;
            this.getVideoDetails(videoId);
        }
    }
    componentWillUnmount() {
        this._Mounted = false;
        try {
            clearInterval(this.state.videoInterval);
            this.props.videoEditUrl('');
        } catch …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-dom react-redux

19
推荐指数
3
解决办法
1万
查看次数

Spring data jpa 按外键和类型搜索过滤器

车型类别车辆

@Column(name="type",nullable=false)
private String type;

@Column(name="last_service_date",nullable=false)
private String lastServiceDate;

@Column(name="seats",nullable=false)
private Long seats;

@Column(name="bags_capacity",nullable=false)
private Long bagsCapacity;

@Column(name="milage",nullable=false)
private Long milage;

//for Franchise object id
private transient Long fId;

@ManyToOne
 @JoinColumn(name="franchise_id")
 private Franchise fkFranchiseId;



@Repository
public interface VehicleRepository extends JpaRepository<Vehicle,Long> 
{


 }
Run Code Online (Sandbox Code Playgroud)

我正在使用 spring data jpa 存储库,想要按类型和foreignKey=>(zipcode) 搜索车辆,我怎样才能找到

在此输入图像描述

spring spring-data-jpa

3
推荐指数
1
解决办法
9346
查看次数

如何解决redux-persist创建同步存储失败的问题。回到 React.js 中的 noop 存储

我的 React 应用程序在客户端渲染中运行良好。出于 SEO 目的,我正在尝试在我的应用程序中实现服务器端渲染。

当我运行 server.js 文件时出现错误。

我该如何解决这个问题? 服务器.js

    import path from 'path';
import fs from 'fs';

const PORT = 8080;
const app = express();

const router = express.Router();
app.use(express.json());

const serverRenderer = (req, res, next) => {
    const content = ReactDOMServer.renderToString(
<Provider store={store}>
<PresistGate presist={presist}>
        <StaticRouter location={req.url} context={{}}>
            <App />
        </StaticRouter>
</PresistGate >
</Provider>
    );
    fs.readFile(path.resolve('../dist/index.html'), 'utf8', (err, data) => {
        if (err) {
            console.error(err);
            return res.status(500).send('An error occurred');
        }
        return res.send(data.replace('<div id="root"></div>', `<div id="root">${content}</div>`));
    });
};
router.use('*', …
Run Code Online (Sandbox Code Playgroud)

express reactjs redux server-side-rendering redux-saga

3
推荐指数
1
解决办法
7667
查看次数