I am very new to react.Problem statement :The selected value is picked from json respose from the backend.The subscription with selected =true in json must remain selected on intial load and across navigations on the screen irrespective of client/server side:
Facing issue :bundle.js:1 Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server: (client) on value="1234" data-reactid="290 (server) on value="1233" data-reactid="290
import React from 'react';
var restUtility = require('../utility/RestUtility');
export default class SummaryHeader extends React.Component {
constructor(props) {
super(props);
this.state = {
value: []
};
this.state=this.props;
this.handleChange = this.handleChange.bind(this);
}
handleChange(value) {
this.setState(value);
console.log('You have selected: ', value);
this.setState({value});
var rootUrl = restUtility.getRootURL();
var requestUrl = rootUrl + '/rest/api/accountSummary/select';
var request = new Request(requestUrl, {
method: 'GET',
// body: data,
headers: { 'subsID': ctnSelected }
});
event.preventDefault();
fetch(request)
.then(function () {
console.log('Invoke rest API : ' + e.target.value);
});
}
render() {
var content;
var ctnList = this.state.accountInfo[0].subsAssociations.map(function (subsAssociation, i) {
if (subsAssociation.subscription.selected) {
content=subsAssociation.subscription.serialNumber;
}
return <option key={i} >{content}</option>;
});
return (
<div className="nameAreaWrapper">
<div> <p style={{ fontSize: 13, float: "left" }}>Your here :</p> <p style={{ fontSize: 13, fontWeight: 700, marginRight: 20, paddingLeft: 5 }}> Account summary</p></div>
<br />
<div style={{ float: "left" }}><h1 style={{ color: '#EA3D17', fontSize: 40 }}>Hello {this.state.contactInfo.firstName}</h1></div>
<div className="chooseNumber"><p style={{ float: "left", paddingRight: 10 }}><b>Choose your number</b></p>
<select className="dropDownStyle" name="MobileNumer" value={content} onChange={this.handleChange}>
{ctnList}
</select>
</div>
</div>
);
}
}
JSON:
"subsAssociations": [
{
"uses": true,
"subscription": {
"serialNumber": "1234",
"selected": false
}
},
{
"uses": true,
"subscription": {
"subscriptionID": "1-50ZB4NR",
"selected": true
}
mainController.js
const express = require('express');
const router = express.Router();
import React from 'react';
import { renderToString } from 'react-dom/server';
import ReactDOM from 'react-dom';
import MainPage from './myaccount/MainPage';
/* GET home page. */
router.get('/', (req, res, next) => {
// res.status(200).send('hello world');
const markup = renderToString(<MainPage/>);
return res.render('index', { markup });
});
module.exports = router;
index-static.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Summary</title>
<link rel="icon" href="./img/favicon.png">
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<div id="main"></div>
<script src="/js/bundle.js"></script>
</body>
</html>