Data binding in React

前端 未结 12 889
心在旅途
心在旅途 2021-01-30 19:49

What I want to do is when I type some text in an input field, it should appear in another place realtime.

Below is my input;



        
12条回答
  •  不要未来只要你来
    2021-01-30 20:37

    There are actually people wanting to write with two-way binding, but React does not work in that way.

    That's true, there are people who want to write with two-way data binding. And there's nothing fundamentally wrong with React preventing them from doing so. I wouldn't recommend them to use deprecated React mixin for that, though. Because it looks so much better with some third-party packages.

    import { LinkedComponent } from 'valuelink'
    
    class Test extends LinkedComponent {
        state = { a : "Hi there! I'm databinding demo!" };
    
        render(){
            // Bind all state members...
            const { a } = this.linkAll();
    
            // Then, go ahead. As easy as that.
            return (
                 
            )
        }
    }
    

    The thing is that the two-way data binding is the design pattern in React. Here's my article with a 5-minute explanation on how it works

提交回复
热议问题