Component State
How do I make an component state?
What is a component state? How do you make a component state? This script and codes were developed by Ruslan Marin on 07 December 2022, Wednesday.
Component State - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Component State</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id="root"></div> <script src='https://npmcdn.com/[email protected]/dist/react.min.js'></script>
<script src='https://npmcdn.com/[email protected]/dist/react-dom.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Component State - Script Codes CSS Codes
body { background: rgba(0, 102, 255, .38); font-family: sans-serif;
}
p { margin: 0 0 1em;
}
article { background: #fff; border: 1px solid rgba(0, 89, 181, .82); width: 50em; margin: 0 0 .5em; box-shadow: 2px 2px 5px -1px rgb(0, 81, 202); padding: 0.5em 1em;
}
.header { text-align: left;
}
.content { text-align: left;
}
.news-author { font-weight: bold; color: #007ddc;
}
.news-text { font-style: italic;
}
.none { display: none !important;
}
Component State - Script Codes JS Codes
"use strict";
// Model
var newsModel = [{ author: "RM", text: "Something has happened", fullText: "Something has happened in a galaxy far, far away"
}, { author: "RM", text: "Something else has happened", fullText: "Our reporters say that something else happened in a galaxy far, far away"
}, { author: "Admin", text: "All our servers are down", fullText: "We're sorry to say that all our servers containing valuable data are down"
}];
// Article component
var Article = React.createClass({ displayName: "Article", getInitialState: function getInitialState() { return { fullTextVisible: false }; }, onMoreClick: function onMoreClick(e) { var _this = this; e.preventDefault(); this.setState({ fullTextVisible: !this.state.fullTextVisible }, /* Optional callback */ function () { console.log(_this.state); }); }, render: function render() { var staticModel = this.props.articledata; var dynamicModel = this.state; return React.createElement( "article", { className: "content" }, React.createElement( "span", { className: "news-author" }, staticModel.author, ": " ), React.createElement( "span", { className: "news-text" }, staticModel.text ), React.createElement( "div", null, React.createElement( "a", { href: "#", className: "news-more", onClick: this.onMoreClick }, "More" ) ), React.createElement( "div", { className: dynamicModel.fullTextVisible ? '' : 'none' }, staticModel.fullText ) ); }
});
// News component
var News = React.createClass({ displayName: "News", render: function render() { var model = this.props.newsmodel; var newsTemplate; if (model.length > 0) { newsTemplate = model.map(function (item, index) { return React.createElement(Article, { articledata: item }); }); } else { newsTemplate = React.createElement( "p", null, "No news" ); } return React.createElement( "div", null, React.createElement( "div", null, newsTemplate ), React.createElement( "div", { className: model.length > 0 ? "" : "none" }, "Всего новостей: ", model.length ) ); }
});
// App component
var App = React.createClass({ displayName: "App", render: function render() { return React.createElement( "section", null, React.createElement( "h3", { className: "header" }, "News" ), React.createElement(News, { newsmodel: newsModel }), " " ); }
});
var container = document.getElementById('root');
ReactDOM.render(React.createElement(App, null), container);
Developer | Ruslan Marin |
Username | marinru |
Uploaded | December 07, 2022 |
Rating | 3 |
Size | 3,702 Kb |
Views | 16,192 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Rotating Cubes with p5.js | 1,753 Kb |
Component Props | 3,113 Kb |
A Pen by Ruslan Marin | 1,561 Kb |
Vue.js Conditional Visibility | 1,520 Kb |
Knockout Lists | 2,531 Kb |
BnW | 1,489 Kb |
Vue.js User Input | 1,565 Kb |
KO Components Demo | 2,994 Kb |
Vue.js Basic Component | 1,566 Kb |
P5.js Clock | 2,414 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Out of the blue | Giaco | 2,537 Kb |
Vanilla JS - A toggleClass function | Woodwork | 2,532 Kb |
Flower expansion | Sreucherand | 3,425 Kb |
Login with flip 3d animation | Mariusbalaj | 3,014 Kb |
Easing | GreenSock | 2,043 Kb |
Virtual vinyl | Davidpanik | 3,474 Kb |
Materializecss input form | Jasonchan | 1,443 Kb |
Wikipedia Viewer | Odylic | 2,333 Kb |
Slider for stackoverflow | KKOKU | 3,222 Kb |
BenU Maintenance Site | Ksherman | 4,893 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!