class FormWidget extends Component {
state={
isFormVisible: false,
};
handleButtonClick = () => {
this.setState(prevState => ({
isFormVisible: !prevState.isFormVisible,
}));
}
render() {
const { isFormVisible } = this.state;
const buttonText = isFormVisible ? 'Hide form' : 'Show form';
return (
<Wrapper>
<Button onClick={this.handleButtonClick}>
{buttonText}
</Button>
<Form isVisible={isFormVisible} />
</Wrapper>
)
}
}
@media only screen and (min-width: 401px) and (max-width: 600px) {
}
var foo = {
bar: 'bar value',
};
console.log(foo.bar);
// => bar value
console['log'](foo['bar']);
// => bar value
var action = 'addClass';
$('.some-selector')[action]('some-class');
$('.some-selector').addClass('some-class');
var key = 'name';
var obj = {
name: 'Tom',
age: 24,
};
console.log(obj[key]);
// => Tom
console.log(obj.name);
// => Tom
console.log(obj[key] === obj.name);
// => true
key = 'age';
console.log(obj[key]);
// => 24
var obj = {
'three words key': 'value',
};
console.log(obj['three words key']);
// => value
import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';
import { someAcion } from '../somePlace';
class App extends Component {
...
componentWillReciveProps(nextProps) {
if (this.props.location !== nextProps.location) {
this.props.someAciton();
}
}
...
}
const mapDispatchToProps = {
someAction,
};
export default withRouter(connect(null, mapDispatchToProps)(App));
const FETCH_USER_DATA_REQUEST = 'FETCH_USER_DATA_REQUEST';
const FETCH_USER_DATA_SUCCESS = 'FETCH_USER_DATA_SUCCESS';
const FETCH_USER_DATA_FAIL = 'FETCH_USER_DATA_FAIL';
export const fetchUserData = () => ({
type: FETCH_USER_DATA_REQUEST,
});
export const fetchUserDataSuccess = data => ({
type: FETCH_USER_DATA_SUCCESS,
payload: data,
});
export const fetchUserDataFail = () => ({
type: FETCH_USER_DATA_FAIL,
});
const initialState = {
data: {},
isLoading: true,
isError: false,
};
export default (state = initialState, action) => {
const { type, payload } = action;
switch (action) {
case FETCH_USER_DATA_REQUEST:
return {
...state,
isLoading: true,
};
case FETCH_USER_DATA_SUCCESS:
return {
...payload,
isLoading: false,
isError: false,
};
case FETCH_USER_DATA_FAIL:
return {
...state,
isLoading: false,
isError: true,
};
default:
return state;
}
};
import { call, put, takeLatest } from 'redux-saga/effects';
import {
FETCH_USER_DATA_REQUEST,
fetchUserDataSuccess,
fetchUserDataFail,
} from '../ducks/userDucks';
import { fetchUserData } from '../api';
export function* fetchUserDataSaga() {
try {
const { data } = yield call(fetchUserData);
yield put(fetchUserDataSuccess(data));
} catch (error) {
yield put(fetchUserDataFail());
}
}
export default function* watchFetchUserDataSaga() {
yield takeLatest(FETCH_USER_DATA, fetchUserDataSaga);
}
export const userDataSelector = state => state.userData;
import User from './User';
import { userDataSelector } from '../selectors';
const mapStateToProps = state => ({
userData: userDataSelector(state),
});
export default connect(mapStateToProps)(User);
import Settings from './Settings';
import { userDataSelector } from '../selectors';
import { fetchUser } from '../ducks/userDucks';
const mapStateToProps = state => ({
userData: userDataSelector(state),
});
const mapDispatchToProps = {
fetchUserData,
};
export default connect(mapStateToProps, mapDispatchToProps)(Settings);
var leftMenu = document.querySelector(".left-menu");
var displayValue = window.getComputedStyle(leftMenu,null).getPropertyValue("display");
console.log(displayValue === 'none');
var someBtn = document.getElementById('all');
someBtn.onclick = function() {
myFunction(5);
}
function myFunction(a){
alert(a);
}
var someBtn = document.getElementById('all');
someBtn.onclick = function() {
alert(5);
}
var someBtn = document.getElementById('all');
someBtn.addEventListener('click', function() {
myFunction(5);
});
function myFunction(a){
alert(a);
}
const array = [{ name: 'John', age: 32}];
const element = { name: 'Sally', age: 25 };
const newArray = [ ...array, element ];
// => [{ name: 'John', age: 32}, { name: 'Sally', age: 25 }]
document.getElementById("myForm").reset();
$('#myForm').trigger("reset");
(state: S, action: A) => S
const isInputActiveReducer = (state = false, action) => {
const { payload, type } = action;
switch(type) {
case TOGGLE_INPUT:
return payload;
default:
return state;
}
}
body: `Hey, ${userName}! You've been notified!`,
body: "Hey, " + userName + "! You've been notified!",
componentDidMount() {
const ideas = firebase.database().ref("items");
let arr = [];
ideas.on("value", snapshot => {
let items = snapshot.val();
for (let item in items) {
arr.push({
id: item,
text: items[item].text
});
}
this.props.renderIdeas(arr);
});
}
Object.keys(obj).map(key => ({ id: key, text: obj[key].text }));