Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anchor Link - Cannot read property 'props' of null #5129

Closed
FacundoGFlores opened this issue Mar 1, 2017 · 3 comments · Fixed by #5143
Closed

Anchor Link - Cannot read property 'props' of null #5129

FacundoGFlores opened this issue Mar 1, 2017 · 3 comments · Fixed by #5143
Assignees

Comments

@FacundoGFlores
Copy link

FacundoGFlores commented Mar 1, 2017

What did you do? Please provide steps to re-produce your problem.

Added conditional rendering to the link:

{props.show && <Link href="#foo" title="foo">}

What do you expected?

Just show the link when prop show is true

What happen?

Error:

Uncaught TypeError: Cannot read property 'props' of null
    at Anchor._this.renderAnchorLink

codepen

http://codepen.io/FacundoGFlores/pen/GWJdNK?editors=001

possible solution

I think it would be easy to solve it just adding:
var href = !!child ? child.props.href : null;

@NE-SmallTown
Copy link
Contributor

@FacundoGFlores Ye,I think it possibly is a bug.But your solution miss some situations.e.g,{arr.length > 0 && <div>zzzz</div>} or {arr.length > 0 && 'xxxxx'}

For your solution,it will still cause error because the elements above don't have props or props.href too.So I think judge the child whether is a instance of Link would be better.

@FacundoGFlores
Copy link
Author

Yes, that's right. But we have to check child twice. First just for child and then for hrefs.

RaoHai added a commit to RaoHai/ant-design that referenced this issue Mar 2, 2017
yesmeck pushed a commit that referenced this issue Mar 2, 2017
@lock
Copy link

lock bot commented May 2, 2018

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators May 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants