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);
axios.defaults.baseURL = API_URL;
const getDefaultHeaders = () => ({
Authorization: `Bearer ${getFromLocalStorage('token')}`,
});
const get = (url, options = {}) => {
const headers = options.headers ?
{ ...options.headers, ...getDefaultHeaders() } : getDefaultHeaders();
return axios.get(`${API_URL}/${url}`, {
...options,
headers,
});
};
const computeStateByProps = ({ yardage, arrList, indxList }) => {
const arrStart = Math.floor(indxList / yardage) * yardage;
if (indxList < arrList.length) {
return {
index: arrStart + yardage,
list: arrList.slice(arrStart, arrStart + yardage),
};
}
return {
index: arrStart - yardage,
list: arrList.slice(arrStart - yardage, arrStart),
};
};
class App extends React.Component {
state = computeStateByProps(this.props);
render () {
return(
....
);
}
}