const accordeonTwo = () => {
const accordeonTwoParent = document.querySelector('#accordion-two'),
accordeonPanelHeading = accordeonTwoParent.querySelectorAll('.panel-heading'),
accordeonPanelContent = document.querySelector('.collapse');
accordeonPanelHeading.forEach((elem) => {
elem.addEventListener('click', (event) => {
event.preventDefault();
let target = event.target;
if (target.closest('.panel-heading')) {
accordeonPanelContent.classList.toggle('in');
}
});
});
};
accordeonTwo();
useEffect(()=>{
...
},[props])
initialState = {
isFetching: false,
data: null,
error: null,
};
const Example = ({ isFetching, error, data }) => {
if (isFetching) return <Preloader />;
if (error) return <Error error={error} />;
if (!data) return null; // или что хотите показывать при отсутствии данных
// далее обращения к ключам data и JSX.
}
onGetWeather(path)
переделайте в getWeather(lat, long)
Сегодня произошла неприятная ситуация, ноутбук упал.
После падения некоторое время все было хорошо, ноут все еще работал, но с видными тормозами
import {Login, LoginWrap, DataInput} from '../styledComponents/login.js'
return(
<LoginWrap>
<Login>
<img src={logo} alt='logo'/>
<h3>Login</h3>
<DataInput>
<input placeholder='Login' ref={loginInput}/>
<input placeholder='Password' type='password' ref={passInput}/>
</DataInput>
<span>{loginError}  </span>
<input type='submit' value='Login' onClick={onLogin}/>
</Login>
</LoginWrap>
)
display: none
в React разработке использовать не принято.const NewsElement = (props) =>{
...
return(
...
<NewsBigScreen display={display} setDisplay={setDisplay} />
...
)
}
const NewsBigScreen = ({ display, setDisplay }) =>{
const closeBigScreen = () =>{
setDisplay('none')
}
return(
<div className='newsBigScreenWrap' style={{display: display}}>
<div className='blackBackground'>
</div>
<div className='NewsBigScreen' >
<input type='submit' onClick={closeBigScreen}/>
</div>
</div>
)
}
this.props.match.param
import * as PropTypes from 'prop-types';
import * as React from 'react';
import { connect } from 'react-redux';
import { RouteComponentProps } from 'react-router-dom';
import { Dispatch } from 'redux';
import { IDispatchProps, StudentActions } from '../../actions/studentActions';
import { IAppState } from '../../types';
import { AnswerForm } from './AnswerForm';
interface IStateProps {
serverConnectError: boolean;
serverDataError: boolean;
authState: boolean;
activeTest: number;
testIssuesList: [object];
testState: [object];
id: number;
}
interface IRouterProps {
id: number;
}
type IProps = IStateProps & IRouterProps;
type TProps = IDispatchProps & IStateProps;
class TesterForm extends React.Component<TProps> {
public static contextTypes = {
router: PropTypes.object,
};
constructor(props: any, context: any) {
super(props, context);
}
public componentWillMount() {
alert(this.props.id);
this.props.studentActions.getTestIssues(this.props.activeTest);
}
public render() {
return(
<div className='row'>
<AnswerForm/>
</div>
);
}
}
function mapStateToProps(state: IAppState, ownProps: RouteComponentProps<IRouterProps>): IProps {
return {
serverConnectError: state.commonReducer.serverConnectError,
serverDataError: state.commonReducer.serverDataError,
authState: state.commonReducer.authState,
activeTest: state.studentReducer.activeTest,
testIssuesList: state.studentReducer.testIssuesList,
testState: state.studentReducer.testState,
id: ownProps.match.params.id, // Здесь передаются параметрвы
};
}
function mapDispatchToProps(dispatch: Dispatch<IDispatchProps>): IDispatchProps {
return {
studentActions: new StudentActions(dispatch),
};
}
const connectApp = connect(mapStateToProps, mapDispatchToProps)(TesterForm);
export {connectApp as TesterForm};
.then(data => dispatch(fetchSuccess(data.success)))
case 'LOGIN_USER_SUCCESS':
return {
...state,
key: action.key,
};
const mapStateToProps = state => ({
success: state.authorisation.key,
});
export default connect(mapStateToProps)(YourComponent);
const { me, user } = this.props;
const isOwner = me.id === user.id;
return (
<>
{isOwner && <Button onClick={this.handleEditClick}>Edit</Button>}
{/* other jsx */}
</>
);
Есть какой-то материал для осознания, как реализовать полноценный логин
@app.route('/test', methods=['POST'])
import React, { useState} from "react";
function App() {
const [value, setValue] = useState("Hello");
const handleClick = (e) => {
setValue(prompt("введите значение", value))
}
return (
<div className="App">
<ul>
<li onClick={handleClick}>{value}</li>
</ul>
</div>
);
}