how to use switch case in react jsx

Solutions on MaxInterview for how to use switch case in react jsx by the best coders in the world

showing results for - "how to use switch case in react jsx"
Basil
17 Apr 2016
1renderSwitch(param) {
2  switch(param) {
3    case 'foo':
4      return 'bar';
5    default:
6      return 'foo';
7  }
8}
9
10render() {
11  return (
12    <div>
13      <div>
14          // removed for brevity
15      </div>
16      {this.renderSwitch(param)}
17      <div>
18          // removed for brevity
19      </div>
20    </div>
21  );
22}
Gabriele
12 Jan 2018
1/* Hint: Use JS IIFE (Immediately invoked function expression) in JSX */
2
3import React from 'react';
4
5import ListView from './ListView';
6import TableView from './TableView';
7
8function DataView({
9	currView,
10	data,
11	onSelect,
12	onChangeStatus,
13	viewTodo,
14	editTodo,
15	deleteTodo,
16}) {
17	return (
18		<div>
19			{(function () {
20				switch (currView) {
21					case 'table':
22						return (
23							<TableView
24								todos={data}
25								onSelect={onSelect}
26								onChangeStatus={onChangeStatus}
27								viewTodo={viewTodo}
28								editTodo={editTodo}
29								deleteTodo={deleteTodo}
30							/>
31						);
32
33					case 'list':
34						return (
35							<ListView
36								todos={data}
37								onSelect={onSelect}
38								onChangeStatus={onChangeStatus}
39								viewTodo={viewTodo}
40								editTodo={editTodo}
41								deleteTodo={deleteTodo}
42							/>
43						);
44
45					default:
46						break;
47				}
48			})()}
49		</div>
50	);
51}
52
53export default DataView;
Bautista
15 Aug 2016
1import * as actionTypes from "../store/actions/actionTypes";
2
3const initialState = {
4  counter: 0,
5  name: "Ginny",
6  tasks: ["cut onion", "drive car"],
7};
8
9const reducer = (state = initialState, action) => {
10  switch (action.type) {
11    case actionTypes.INCREMENT:
12      return {
13        ...state,
14        counter: state.counter + 1,
15      };
16    case actionTypes.DECREMENT:
17      return {
18        ...state,
19        counter: state.counter - 1,
20      };
21    case actionTypes.ADD:
22      return {
23        ...state,
24        counter: state.counter + action.value,
25      };
26    case actionTypes.ADD_TEN:
27      return {
28        ...state,
29        counter: state.counter + action.payload,
30      };
31    default:
32      return state;
33  }
34};
35
36export default reducer;
37
queries leading to this page
switch case react renderswitch case react component renderuse of switch statement in react jsswitch inside react componentswitch case in react renderswitch case in render reacthow to make a switch case in jsxreact case switch not workingswitch button in reactswitch react componentreactjs switch not changeswitch button in react jsswitch block in jsxswitch case reactswitch statement with react carohow to use switch in react jsswitch from js to jsxsetting conditions in switch case in react class componentswitch case in javascript reactswitch in jsxget switch value in reactreact switch casereact switch component not workswitch case react buttonreactjs switch casereact 3cswitch 3eswitch react jshow to use switch case in jsxwhat does the switch statement do reactswitch case in react js renderswitch in jsx reacthow to use switch case in react jsjavascript switch case return react syntaxreact switch case going to default alwaysjsx switch case statement not workingswitch button react jsswitch case statemtent in reacswitch case not working reactswitch case react componentswitch in reactswitch react rotuerassign components in react with switch caseswitch react renderswitch components reactreact switch not workingswitch inside jsxreact switch in renderreact return switch casework with switch button in reactswitch case in return reactreact switch case default 22switch react js 22switcher in reacthow to use switch button in react jsreact switch inside renderswitch case in react jsreact switch statement renderswitch statement is not working in react componentswitch in react functional componentswitch statement jsx functional componentswitch react exampleswitch render reactreactjs switch what isreact switch statehow to make switch in reactswitch case in reactuse switch in react jsswitch case statement reactswitch statement not working in reactreact switch statement case with or operatorreact switch case not workingsyntax of switch statement react nativeswitch reactjsreact switchwriting switch statement in reactreact switch case rendercase switch react function componentsswitch case not working in reactswitch case in jsxswitch button reactswitch reac jsjsx switchreact native switch case in renderreact switch doesn 27t turnswitch in react 7b 7dusing switch case reactswitch case not working react nativereact switch statementswitch case in react jsxreact render switch caseswitch statement jsxhow to switch to jsxreact switch statement functional componentreact case switchjsx switch default not workingusing switch statement in reactjsswitch statement in jsxcan i switch in a jsx statementreact switch exampleswitch component reactdo you still need to use switch in reactswitch cases reacthow to make switch case in reactswitch button reactjsusing switch in reactswitch is not working in react jsreact switch case componentreact switch case in componentswitch case in jsx react jsswitch examples reactcomponent switch reactreact switch case not working on returnhow to return switch statement in functional component in reactreact switch componentswitch case not working reatcjsswitch in react for components why use switch in react switch in react jsreact switch statementsswitch case react return reactswitch in jsx returnhow to switch components in react switch case in react functional componentreact js switchhow to render throuth switch case in react 3fwhat does switch does in reacthow to use switch case in react jsxhow to render switch statement in react return functionswitch case return jsxswitch jsxreact switch within returnswitch statement in reactswitch loop reactswitch is not working react nodereact 3a return with switchjs switch case not getting react stateswitch case react 7c 7creturn componenet in switch reactwhat is switch in reactwhat is a switch in reactswitch react not workingswitch case syntax reactuse switch case in react jsswitch in app jsxreact use switch in renderswitch case in react class componentswitch case react jsreact switch uttonswitch case render reactreactjs switch statementreact switch case with or conditionjsx switch caseswitch reactswitch case not workin in reactswitch statement react componentswitch to react jsusing a switch case for return render reactswitch statement reactwhat is switch component in reactreactjs switch component 22switch statemanet react js 22react switch stattement in returnswitch case break in react jshow to use switch case in react jsx