Какой объект принимает react-dom?
console.log('Root ReactElement: ', <MyRootСomponent />);
users.push(this.user);
let lastUser = users[users.length - 1];
function decorator(f) {
return function() {
f.apply(this, arguments);
console.log(f.name + ' is called!');
}
}
function foo() {
console.log('I am foo!');
}
const bar = decorator(foo);
bar(); // I am foo! \n foo is called!
function foo() {
foo.isRunning = true;
// do something
}
function bar() {
if (!foo.isRunning) {
return foo();
}
// do something other
}
var textarea = document.querySelector('.textarea-field textarea');
console.log('tag name', textarea.tagName); // TEXTAREA
console.log('tag name to lowercase', textarea.tagName.toLowerCase()); // textarea
var arrValue = JSON.parse(sessionStorage[key]);
interface AppStorage {
get: (key: string) => any;
set: (key: string, value: any, options: any) => void;
delete: (key: string) => void;
}
const obj = {};
_.set(obj, 'user.id', 5);
console.log(obj); // { user: { id: 5 } }
const AuthRoute = ({ component: Component, render, isSignedIn, ...rest }) => (
<Route {...rest} render={props => {
if (!isSignedIn) return (
<Redirect to={{
pathname: "/signin",
state: { referrer: props.history.location.pathname }
}} />
);
if (render) return render({ ...props });
return <Component {...props} />;
}} />
);
const mapStateToProps = state => ({
isSignedIn: isSignedInSelector(state),
});
export default connect(mapStateToProps)(AuthRoute);
<AuthRoute path="/admin" component={Admin} />
<Switch>
{isSignedIn && <Route path="/admin" component={Admin} />}
<Route path="/partner/:name" component={Partner}/>
<Route component={() => <div>page not found</div>} />
</Switch>
const test = config => someAsyncCall().then(bar => ({ ...config, bar }));
const config = { foo: 123 };
test(config).then(console.log); // { foo: 123, bar: 456 };
const test = async function(config) {
const bar = await someAsyncCall(); // returns 456
return { ...config, bar };
}
(async () => {
const config = { foo: 123 };
const newConfig = await test(config);
console.log(newConfig); // { foo: 123, bar: 456 };
})();
createItem(task) {
this.setState(prevState => ({
tasks: [
...prevState.tasks,
{ name: task, status: false },
],
}));
}
static getDerivedStateFromProps(props, state) {
if (props.data !== state.data) {
return {
data: props.data,
};
}
return null;
}