For example, I have a react.js component named Question
which need the props title
,id
,content
.
<div id="main-section">
<div id="question"></div>
</div>
ReactDOM.render(
<Question id="xxxx" title="xxx" content="xxx"/>,
document.getElementById('question')
);
I come up with two methods:
- design an restful api, everytime the web need to render a question, make an ajax request to the server to get the props.
- store the props in dom element and get these props before rendering.
What's the best practise to do such thing? is there any other better method?