0

Is it possible to render the react component just by referencing it with its name. For example:

<div>
   <MyComponent/>
</div>

All the illustrations and tutorials I have seen, they use ReactDOM.render function to render the component to the target HTML element. But what if I want to repeat the rendering of the component based on server data like this:

<div>
   <?php foreach($items as $item):?>
      <MyComponent passedData="<?=$item['name'];?>"/>
  <?php endforeach;?>
</div>

I know I can use componentWillMount method to request the data from a web service and then render the desired HTML but my application is not in this model (does not use web services). The data gets passed from controller to view and view will render the component n number of times based items count queried from database.

Is that possible?

PS: I am new to react and this is my application in react so apologies if I have missed something in tutorials and documentation.

Thanks.

2
  • You are looking into server-side rendering. Commented Apr 22, 2017 at 10:51
  • NB: Vue can do this without server side rendering by now. Maybe the answer should be updated? Commented Dec 21, 2020 at 21:44

1 Answer 1

1

This is server-side rendering. If you'are using PHP you can use react-php-v8j.

v8js is required on your server.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @jonathandion
Vue can do this with vue-cli-service and wc target (web component). Is anything similar supported by React by now?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.