Skip to content

Instantly share code, notes, and snippets.

import { createSelector } from 'reselect'
// supports passing in the whole obj or just the string to correct the video type
const fixVideoTypeNaming = (videoType) => {
let video = videoType
// If video is a video object
if (video && typeof video === 'object') {
const media = { ...video }
video = media.videoType
const withTotalCount = (WrappedComponent) => {
class WithTotalCountContainer extends React.Component {
componentDidMount = () => {
const { total, dispatch } = this.props
if (total == null) {
dispatch(fetchTotalVideoTypeCount())
}
}
render() {
const TotalVideoCount = ({ classes, total, fetching, fetchError }) => {
if (fetching) return <LoadingSpinner />
const hasResults = !!total
const noResults = fetched && !total
const errorOccurred = !!fetchError
return (
<Typography
variant="h3"
export const getOverallSelector = (state) =>
state.app[fixVideoTypeNaming(state.app.media.video.videoType)].options.total
.overall
export const getSpecificWeekSelector = (state, props) =>
state.app[fixVideoTypeNaming(state.app.media.video.videoType)].options.weekly[
props.date
]
const SomeComponent = ({ children, items = {}, isVisible }) => (
<div>
{Object.keys(items).length ? (
<DataTable items={items} />
) : (
<h2>Data has not been received</h2>
)}
</div>
)
"TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at yazeyafabu.js:4:45
at https://static.jsbin.com/js/prod/runner-4.1.7.min.js:1:13924
at https://static.jsbin.com/js/prod/runner-4.1.7.min.js:1:10866"
render() {
const { arr } = this.props
return (
<div>
{arr && arr.map()...}
</div>
)
}
const api = {
async getTotalFrogs() {
return {
data: {
result: [
{ name: 'bob the frog', tongueWidth: 50, weight: 8 },
{ name: 'joe the other frog', tongueWidth: 40, weight: 5 },
{ name: 'kelly the last frog', tongueWidth: 20, weight: 2 },
],
},
const api = {
async getTotalFrogs() {
return {
data: {
result: [
{ name: 'bob the frog', tongueWidth: 50, weight: 8 },
{ name: 'joe the other frog', tongueWidth: 40, weight: 5 },
{ name: 'kelly the last frog', tongueWidth: 20, weight: 2 },
],
},
const api = {
async getTotalFrogs() {
return {
data: {
result: [
{ name: 'bob the frog', tongueWidth: 50, weight: 8 },
undefined,
{ name: 'kelly the last frog', tongueWidth: 20, weight: 2 },
],
},