question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: undefined is not an object (evaluating 'this._layouts[i].x')

See original GitHub issue

I’m trying to implement search (as the user types in the search box) on the list. However, I’m getting the following error TypeError: undefined is not an object (evaluating 'this._layouts[i].x').

When the search string (value) is empty and the list is updated with all the elements, the error occurs. I also tried different conditions such as returning originalList when value is ‘’, but it throws the same error as the list is updated with all the elements.

This is my code-

constructor(props) {
	super(props);
	let list = [{ name: 'Item1' }, { name: 'Item2' }];

	this._dataProvider = new DataProvider((r1, r2) => {
		return r1.name !== r2.name;
	});

	this.state = {
		list,
		originalList: _.clone(list),
		dataProvider: this._dataProvider.cloneWithRows(list)
	};
}

search(value) {
	this.setState(prevState => {
		return {
			list: _.filter(prevState.originalList, item=> {
				return value == '' || _.includes(item.name, value);
			})
		};
	});
}

render() {
	return (
		<Input
			placeholder="Search"
			autoFocus
			onChangeText={value => {
				this.search(value);
			}}
		/>
		<RecyclerListView
			layoutProvider={this._layoutProvider}
			dataProvider={this.state.dataProvider.cloneWithRows(this.state.list)}
			rowRenderer={this._rowRenderer.bind(this)}
		/>
	);
}

Any help would be much appreciated.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

2reactions
keshavhubcommented, Feb 3, 2019

Hey @sksin28 Thanks for pointing out this issue but even after making the change you recommended, still the issue exists. I got a workaround(hack) for this but still didn’t find a good solution.

2reactions
sksin28commented, Sep 27, 2018

The issue has been resolved. The dataprovider was not passed correctly which I believe resulted in dataprovider and list not being in sync.

So that no one else faces this issue, this is what my earlier code looked like-

import * as React from "react";
import { Text, View, TextInput } from "react-native";

import _ from "lodash";

import {
  DataProvider,
  LayoutProvider,
  RecyclerListView
} from "recyclerlistview";

export default class App extends React.Component {
  constructor(props) {
    super(props);

    let list = [{ name: "Item 1" }, { name: "Item 2" }];

    this._dataProvider = new DataProvider((r1, r2) => {
      return r1.name !== r2.name;
    });

    this._layoutProvider = new LayoutProvider(
      index => {
        return 1;
      },
      (type, dim) => {
        dim.width = 400;
        dim.height = 120;
      }
    );

    this.state = {
      list,
      originalList: _.clone(list),
      dataProvider: this._dataProvider.cloneWithRows(list)
    };
  }

  search(value) {
    this.setState(prevState => {
      return {
        list: _.filter(prevState.originalList, item => {
          return value == "" || _.includes(item.name, value);
        })
      };
    });
  }

  _rowRenderer(type, item) {
    return (
      <View>
        <Text>{item.name}</Text>
      </View>
    );
  }

  render() {
    return (
      <View style={{ marginTop: 50, width: 400, height: 400 }}>
        <TextInput
          style={{ width: "100%" }}
          placeholder="Search"
          placeholderTextColor="red"
          onChangeText={value => {
            this.search(value);
          }}
        />
        <RecyclerListView
          layoutProvider={this._layoutProvider}
          dataProvider={this.state.dataProvider.cloneWithRows(this.state.list)}
          rowRenderer={this._rowRenderer.bind(this)}
        />
      </View>
    );
  }
}

After changing the dataprovider property, the code looks like-

import * as React from "react";
import { Text, View, TextInput } from "react-native";

import _ from "lodash";

import {
  DataProvider,
  LayoutProvider,
  RecyclerListView
} from "recyclerlistview";

export default class App extends React.Component {
  constructor(props) {
    super(props);

    let list = [{ name: "Item 1" }, { name: "Item 2" }];

    this._dataProvider = new DataProvider((r1, r2) => {
      return r1.name !== r2.name;
    });

    this._layoutProvider = new LayoutProvider(
      index => {
        return 1;
      },
      (type, dim) => {
        dim.width = 400;
        dim.height = 120;
      }
    );

    this.state = {
      list,
      originalList: _.clone(list)
    };
  }

  search(value) {
    this.setState(prevState => {
      return {
        list: _.filter(prevState.originalList, item => {
          return value == "" || _.includes(item.name, value);
        })
      };
    });
  }

  _rowRenderer(type, item) {
    return (
      <View>
        <Text>{item.name}</Text>
      </View>
    );
  }

  render() {
    return (
      <View style={{ marginTop: 50, width: 400, height: 400 }}>
        <TextInput
          style={{ width: "100%" }}
          placeholder="Search"
          placeholderTextColor="red"
          onChangeText={value => {
            this.search(value);
          }}
        />
        <RecyclerListView
          layoutProvider={this._layoutProvider}
          dataProvider={this._dataProvider.cloneWithRows(this.state.list)}
          rowRenderer={this._rowRenderer.bind(this)}
        />
      </View>
    );
  }
}

@naqvitalha Thanks anyways.

Read more comments on GitHub >

github_iconTop Results From Across the Web

undefined is not an object (evaluating 'M.layout.force') - Stack ...
I'm new to JSNetworkX. I created a graph using the examples from jsnetworkx.org but I can only log it, I can't display it....
Read more >
undefined is not an object (evaluating 'layout.levels[intersect[0 ...
I am generating a diagram programmatically and now getting this quite often: TypeError: undefined is not an object (evaluating ...
Read more >
LWC - TypeError: undefined is not an object (evaluating 'e ...
TypeError : undefined is not an object (evaluating 'e.detail.value'). Functions are all working, but throwing me this error. Any idea of why and...
Read more >
Error: undefined is not an object (evaluating 'i.status') when ...
So I'm trying to register a user manually using velo. I followed the documentation pretty closely but I still get this error: Error:...
Read more >
TypeError: undefined is not an object (evaluating 'b.prototype')
[This thread is closed.] Getting this console error on frontend user profiles TypeError: undefined is not an object (evaluating 'b.…
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found