Reputation: 393
I want to convert a complex div container done by a web designer in pure HTML into a React component. This div container has states for React to manage. I know I can convert the div to JSX but that would mean double work for both designer and myself. dangerouslySetInnerHTML doesn't handle states. The idea is that I can create subclass of React.Component, define states and render the state values into the div container without using JSX?
Here's a snippet of the div container markup:
<div id="activities_panel" class="panel">
<div class="panel-body nav-tabs-animate nav-tabs-horizontal" data-plugin="tabs">
<ul class="nav nav-tabs nav-tabs-line" role="tablist">
<li class="nav-item" role="presentation">
<a aria-controls="activities" class="active nav-link" data-toggle="tab" href="#activities" role="tab">Activities <span class="tag tag-pill tag-danger">5</span></a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active animation-slide-left" id="activities" role="tabpanel">
<ul class="list-group">
<li class="list-group-item">
<div class="media">
<div class="media-left">
<a class="avatar" href="javascript:void(0)"><img alt="..." class="img-fluid" src="avatar1.jpg"></a>
</div>
<div class="media-body">
<h4 class="media-heading">Avatar 1 <span>posted an updated</span></h4><small>active 14 minutes ago</small>
<div class="profile-brief">
“Test test”
</div>
</div>
</div>
</li>
</ul>
<a class="btn btn-block btn-default profile-readMore" href="javascript:void(0)" role="button">Show more</a>
</div>
</div>
</div>
</div>
Upvotes: 0
Views: 646
Reputation: 2555
A few tips to convert your big div into React component:
<activities-panel>
as the container, <nav-tabs>
and <tab-content>
as children. Of course, you can create more sub-level components if you wish which makes the maintenance easier. class
to className
props
. So the container <activities-panel>
will manage the state of the component.dangerouslySetInnerHTML
if possible.<button>
for buttons and <a>
for links so it is more accessible.Upvotes: 1