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.

How can I change a property in a stateless component?

See original GitHub issue

I have a stateless component: <Button fired={fired} onClick={() => setState('fired': true)} /> how can I change fired property when I click on the button?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

25reactions
arunodacommented, May 17, 2016

May be we need to have some kind of reactive variables where we can change values. How about this:

{ storiesOf, ReactiveVar } from '@kadira/storybook';

const fired = new ReactiveVar(false);

storiesOf('Button')
  .add('simple-button', () => {
    <Button fired={fired.get()} onClick={fired.set(!fired.get())} />
  })

Once you set the value, the related story will get re-rendered again. This can be even built completely outside of @kadira/storybook if we expose an API to reload the story.

9reactions
jdelStrothercommented, May 16, 2016

Maybe wrap your button in a stateful component? eg:


const ButtonWrapper = React.createClass({
  render() {
     return <Button fired={fired} onClick={() => setState('fired': true)} />
  }
})

storiesOf('button', module)
  .add('', () => (<ButtonWrapper/>)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Change Props in Stateless React.js Components ... - Pluralsight
This guide will analyze the primary role of props in a React.js component, how it is different from state , and when to...
Read more >
Stateless Components From Stateful Components Cheatsheet
In React, a component should never change its own props directly. A parent component should change them. State, on the other hand, is...
Read more >
How do I pass properties to stateless/functional components?
I want to pick up the lang property inside that component. Why is the variable undefined when I render it in <TestBundle />...
Read more >
Learn Stateful and Stateless components in ReactJS - CronJ
It allows you to create components that are interactive and reusable. It is mutable and can only be changed by using setState() method....
Read more >
Stateful and Stateless Components in React
Notice the stateless component is written as a function. As cool as state is, you should always aim to make your components as...
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