我正在使用Webpack,Redux和ReactJS。如何将html转换为JSX,ReactJS组件?
目前我在我的index.html
中设置了以下设置,但我想将其转换为JSX,ReactJS组件。什么是正确和正确的方式来做到这一点?
而且在我index.html
<head/>
,有一类辅助函数称为classie.js
:
<script src="classie.js"></script>
<script>
function init() {
window.addEventListener('scroll', function(e){
var distanceY = window.pageYOffset || document.documentElement.scrollTop,
shrinkOn = 300,
header = document.querySelector("header");
if (distanceY > shrinkOn) {
classie.add(header,"smaller");
} else {
if (classie.has(header,"smaller")) {
classie.remove(header,"smaller");
}
}
});
}
window.onload = init();
</script>
在我index.html
<body/>
:
<div id="wrapper">
<header>
<div class="container clearfix">
<h1 id="logo">
Practice Navigation Bar
</h1>
<nav>
<a href="">Button 1</a>
<a href="">Button 2</a>
</nav>
</div>
</header>
</div>
所以它转换成类似下面ReactJS组件格式:
//App.js
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import actions from '../redux/actions'
class NavBar extends Component {
render() {
return (
<div>
{/*e.g. What should go in here?*/}
</div>
);
}
}
function mapStateToProps(state) {
return state
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(actions, dispatch)
}
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(NavBar)
提前谢谢!
这些都是正确的假设! 'classie.js'应该放在哪里,它曾经在我的'index.html''