PaulLeCam / react-leaflet

React components for Leaflet maps
https://react-leaflet.js.org
Other
5.13k stars 884 forks source link

Dynamic props not translating to view after state change with redux #149

Closed mr-romeijn closed 8 years ago

mr-romeijn commented 8 years ago

Please make sure to check the following boxes before submitting an issue. Thanks!

Dynamic props automatically updating path

Actual behavior

They're not being updated at all. Props are actually being updated by redux but Leaflet dynamic prop changes aren't being displayed. (New multiPolyLine isn't being drawn when polylines prop changes.

getLatLngarray(GmapDirectionData){
 //pseudo code (works properly)
 return { rootList: array(withLatLngObjects) }
}

getMap() {
                var obj = this.getLatLngarray(this.props.dashboard);
                const position = obj.start;
                console.log("GETTING MAP", "RE-RENDER");
                return (<Map ref="map" style={style.map} center={position} zoom={13}>
                    <TileLayer
                        url='http://{s}.tile.osm.org/{z}/{x}/{y}.png'
                        attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
                    />
                    <Marker position={position}>
                        <Popup>
                            <span>A pretty CSS3 popup.<br/>Easily customizable.</span>
                        </Popup>
                    </Marker>
                    {this.getMarkers(obj.endLocations)}
                    <Path fill={true}>
                        <MultiPolyline polylines={obj.rootList}></MultiPolyline>
                    </Path>
                </Map>)
    }

retrieveDirectionDataFor(){
 //REDUX ACTION (Triggers state change)
 this.props.getDirections(this.refs.driverId.value);
}

render(){
<select ref="driverId" onChange={this.retrieveDirectionDataFor.bind(this)}>
        <option value="">Select a driver...</option>
        {Drivers.map(function (e) {
                return (<option value={e.driver_number}>{e.name}</option>)
        })}
</select>
  this.getMap()
}

So as seen in above code there's a simple dropdown which changes the component state when changed. All the props get updated properly (tested) and It also triggers the render method accordingly; but it doesn't reflect on the leaflet map.

--Editted (Added code samples)

Redux, React-leaflet

PaulLeCam commented 8 years ago

Please provide steps to reproduce / example code.

mr-romeijn commented 8 years ago

Added code samples

PaulLeCam commented 8 years ago

Hard to say what could be the issue looking at your code, but here is a working example of dynamic polylines and color: http://jsfiddle.net/mf9z320t/ Unless there is a very particular edge case, I expect the issue is likely with your application not injecting the needed data to the components.